Negative doubles or floats in Haskell (macports)

a 夏天 提交于 2019-11-28 08:40:43

问题


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

回答1:


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.

  • Info: http://hackage.haskell.org/platform/
  • Link: http://hackage.haskell.org/platform/mac.html



回答2:


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.




回答3:


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.




回答4:


Works for me on 6.12.3. Could be a bug in that version.



来源:https://stackoverflow.com/questions/4101599/negative-doubles-or-floats-in-haskell-macports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!