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 type rational (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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -