I run through a Brief Introduction to Haskell and have come to currying . (So, correct all the mistakes I made in the terminology.)
This section says:
Here is a function with two arguments defined in the usual way. Prelude> let myadd x y = x + y
Prelude> myadd 3 4
7
And then a little further:
Here is the third equivalent way to define myadd, since an anonymous function returns another anonymous function. Prelude> let myadd = \x -> \y -> x + y
Prelude> :t myadd
myadd :: Integer -> Integer -> Integer
Despite the fact that he says “equivalent”, unexpectedly (for a beginner like me), this is not so, because the type is myaddmore general:
Prelude> :t myadd
myadd :: Num a => a -> a -> a
Prelude> myadd 1.5 2.5
4.0
Prelude> myadd3 1.5 2.5
<interactive>:12:8:
No instance for (Fractional Integer) arising from the literal `1.5'
Possible fix: add an instance declaration for (Fractional Integer)
In the first argument of `myadd3', namely `1.5'
In the expression: myadd3 1.5 2.5
In an equation for `it': it = myadd3 1.5 2.5
source
share