3
I’m studying Haskell, and I don’t understand why this code doesn’t compile:
foo :: Int -> Double -> Double
foo a b = a+b
The error message is:
Couldn't match expected type `Double' with actual type `Int'
In the first argument of `(+)', namely `a'
In the expression: a + b
In an equation for `foo': foo a b = a + b
I know the operator '+' is a function with the parameters
(+) :: (Num a) => a -> a -> a
but Int and Double types are instances of Num.
So, why does the compiler not accept this code??
Thank you very much!
There are no instances in functional languages in the same way as in procedural languages; Num is a class in the sense that there are types that belong to it, but it does not mean that they are equivalent.
– Marcelo Shiniti Uchimura