Why is so hard to deal with Number in Haskell
Division will never work in Haskell:)
If you have two Integer a, b
a/b gets error
It works only if you do that:
(fromIntegral a) / (fromInteger b)
because / is defined under Fractional
-- convert from Integral to Integer
class (Real a, Enum a)=> Integral a where
toInteger:: a -> Integer
-- convert from Integer to Num a
class (Num a)=> a where
fromInteger:: Integer -> a
-- converts from Integer to polymorphic type: Num
let a = 3::Integer
let b = 2::Integer
a/b gets error
class (Num a)=>Fractional a where
(/):: a -> a -> a
(fromIntegral a) / (fromInteger b)
fromIntegral::(Integral a, Num b)=> a -> b
fromIntegral = fromInteger . toInteger
toInteger::(Real a, Enum a)=> a -> Integer
fromIntegral::(Num a)=>Integer -> a
-- (Real a, Enum a) -> (Num b)
fromIntegral . toInteger::(Real a, Enum a, Num b)=> a -> b
(Num a) => Fractional a
(Num a, Ord a) => Real
(Real a, Enum a) => Integral
(Num a, Orda a, Enum a) => Integral
(Real a, Enum b) => Integral
fromIntegral . toInteger::(Integral a, Num b)=> a -> b