Haskell 中的负双精度数或浮点数 (macports)
当我尝试显示负双精度或浮点数时,为什么会出现分段错误?负整数没有问题。
Prelude> let a = 4
Prelude> :t a
a :: Integer
Prelude> let b = -4
Prelude> b
-4
Prelude> :t b
b :: Integer
Prelude> let c = 5.6
Prelude> :t c
c :: Double
Prelude> let d = -5.6
Prelude> :t d
d :: Double
Prelude> show d
"-Segmentation fault
我尝试了各种方法,似乎数字被正确理解但没有显示。版本信息:
ghci --version
The Glorious Glasgow Haskell Compilation System, version 6.10.4
Why do I get a segmentation fault when I try to show a negative double or float? There is no problem for negative integers.
Prelude> let a = 4
Prelude> :t a
a :: Integer
Prelude> let b = -4
Prelude> b
-4
Prelude> :t b
b :: Integer
Prelude> let c = 5.6
Prelude> :t c
c :: Double
Prelude> let d = -5.6
Prelude> :t d
d :: Double
Prelude> show d
"-Segmentation fault
I tried it various ways, it seems that the number is correctly understood but not shown. Version info:
ghci --version
The Glorious Glasgow Haskell Compilation System, version 6.10.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
MacPorts 上的 GHC 似乎已损坏。请参阅 https://trac.macports.org/ticket/25265
考虑从 haskell.org 安装 Haskell 平台,该平台包括 GHC 6.12.3 和一系列 Haskelly 好东西。
GHC on MacPorts seems to be broken. See https://trac.macports.org/ticket/25265
Consider instead installing the Haskell Platform from haskell.org, which includes GHC 6.12.3 and a bundle of Haskelly goodies.
您应该认识到的最重要的事情是 Haskell 中决不应该发生分段错误。它的类型系统确保在运行时不会“出错”。如果您确实看到分段错误,那么要么您的 Haskell 编译器中存在错误,要么您正在使用 Haskell FFI 连接 C 代码,而您的 C 代码出现了问题。然而,在纯 Haskell 代码中,您永远不应该看到这一点。
The most important thing you should realise is that segmentation faults should never occur in Haskell. Its type system ensures that nothing like that "goes wrong" at runtime. If you do see a segmentation fault then either there is a bug in your Haskell compiler or you're interfacing to C code with the Haskell FFI and something has gone wrong with your C code. In pure Haskell code, however, you should never see this.
2011 年 3 月:此问题已在 Haskell 平台 的 GHC 7 版本中修复,其中32 位和 64 位 Mac 本机端口状况良好。
March 2011: This is fixed in the GHC 7 release of the Haskell Platform, where both 32 bit and 64 bit Mac native ports are in fine condition.
在 6.12.3 上为我工作。可能是该版本的错误。
Works for me on 6.12.3. Could be a bug in that version.