I want to write a function mapsucc that produces the successor of every item in a list. Easy enough:
mapsucc xs = map succ xs
works perfectly. I think I could use Currying to make this definition even shorter:
mapsucc = map succ
but I get:
No instance for (Enum b0) arising from a use of ‘succ’
The type variable ‘b0’ is ambiguous
Relevant bindings include
mapsucc :: [b0] -> [b0] (bound at mapsucc.hs:1:1)
Note: there are several potential instances:
instance Enum Ordering -- Defined in ‘GHC.Enum’
instance Enum Integer -- Defined in ‘GHC.Enum’
instance Enum () -- Defined in ‘GHC.Enum’
...plus six others
In the first argument of ‘map’, namely ‘succ’
In the expression: map succ
In an equation for ‘mapsucc’: mapsucc = map succ
Now, it's not clear to me why the curried version should be ambiguous, and why, instead, the one with explicit parameters is not.
Also, if from ghci I declare mapsucc with a let, it works perfectly:
Prelude> let mapsucc = map succ
Prelude> mapsucc "hello"
"ifmmp"
Same behavior if I redefine succ:
mysucc x = succ x
works perfectly, while
mysucc = succ
gives the same error:
No instance for (Enum a0) arising from a use of ‘succ’
The type variable ‘a0’ is ambiguous
Relevant bindings include
mysucc :: a0 -> a0 (bound at mapsucc.hs:3:1)
Note: there are several potential instances:
instance Enum Ordering -- Defined in ‘GHC.Enum’
instance Enum Integer -- Defined in ‘GHC.Enum’
instance Enum () -- Defined in ‘GHC.Enum’
...plus six others
In the expression: succ
In an equation for ‘mysucc’: mysucc = succ
and, again, if I define mysucc in ghci throug a let, it works perfectly:
Prelude> let mysucc = succ
Prelude> mysucc 3
4