简体   繁体   中英

Haskell: Point-free style

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM