class - What's the difference between "float" and "fractional" in Haskell? -
prelude> let c=[1.0,2.0] prelude> :t c c :: fractional t => [t]
i'd expect "c" list of either num or float. why fractional? there implicit type conversion going on here in haskell?
you can make happen:
> :set -xnumdecimals > let c=[1.0,2.0] > :t c c :: num t => [t]
the answer "why fractional
" "because report says so":
float → decimal . decimal [exponent] | decimal exponent
a floating literal stands application of
fromrational
value of typerational
(that is,ratio integer
). given typings:frominteger :: (num a) => integer -> fromrational :: (fractional a) => rational ->
integer , floating literals have typings
(num a) => a
,(fractional a) => a
, respectively.
i guess report says because nice simple rule explain: no dot/exponent, it's num
-polymorphic, yes dot/exponent, it's fractional
-polymorphic.
two relevant bits are:
https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-190002.5
https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1360006.4.1
Comments
Post a Comment