Why does the first one fails while the latter one succeeds in compilation?
I expect foo
and foo'
are equivalent, that is, foo'
is just a point-free function
of foo
:
foo :: [a] -> [a] -> [(a,a)]
foo = map id . zip
foo' :: [a] -> [a] -> [(a,a)]
foo' a b = map id $ zip a b
But foo
fails with following error:
Couldn't match type ‘[b0] -> [(a, b0)]’ with ‘[b]’
Expected type: [a] -> [b]
Actual type: [a] -> [b0] -> [(a, b0)]
Relevant bindings include
foo :: [a] -> [b] (bound at <interactive>:26:5)
Probable cause: ‘zip’ is applied to too few arguments
In the second argument of ‘(.)’, namely ‘zip’
In the expression: map id . zip
Any comments will be appreciated.
If you look at the definition/type signature of (.)
you see that its arguments are functions with a single parameter. But zip
has two thus you have to supply at least one parameter to make it equivalent
foo a = map id . zip a