Hello everyone,I am just starting with Haskell so please bear with me.
Here's my question:
Consider the below definition / output:
Prelude> :t (+)(+) :: (Num a) => a -> a -> a
What I understand from the above is that "+" is a function that takes two argswhich are types of anything that IS-AN instance of "Num" (Int, Integer, Float, Double)and returns an instance of "Num".Hence this works fine:Prelude> 4.3 + 26.3
But I can't understand why this doesn't work:Prelude> 4.3 + 4 :: Int
<interactive>:1:0:No instance for (Fractional Int)arising from the literal `4.3' at <interactive>:1:0-2Possible fix: add an instance declaration for (Fractional Int)In the first argument of `(+)', namely `4.3'In the expression: 4.3 + 4 :: IntIn the definition of `it': it = 4.3 + 4 :: Int
I expected that the second addition would work as both "Float" and "Int" areinstances of "Num". Is it that since both the formal args are defined as "a" theyhave to be exactly the same instances? Had "+" been defined something like:(+) :: (Num a, Num b) => a -> b -> amy second addition would have worked?
Please let me know what I am missing.
Regards,Venu Chakravorty.
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners