fromIntegral :: (Integral a, Num b) => a -> b
takes one arg. The =>
should be read as a logical implication with universal quantification:
for all types
a
andb
,if
a
is an instance ofIntegral
andb
is an instance ofNum
,then
fromIntegral
can take ana
and produce ab
.
This function converts a value of type a
(which is an Integral
type) to the b
type (which is an instance of the more general Num
class). E.g. you cannot add the integer 1
to the float 2
in Haskell without converting the former:
Prelude> (1 :: Int) + (2 :: Float)
<interactive>:10:15:
Couldn't match expected type `Int' with actual type `Float'
In the second argument of `(+)', namely `(2 :: Float)'
In the expression: (1 :: Int) + (2 :: Float)
In an equation for `it': it = (1 :: Int) + (2 :: Float)
Prelude> fromIntegral (1 :: Int) + (2 :: Float)
3.0