Haskell:无点风格

时间:2016-01-31 08:31:42

标签: haskell pointfree

为什么第一个失败而后者成功编译?

我希望foofoo'是等价的,也就是说,foo'只是一个无点函数 foo

foo :: [a] -> [a] -> [(a,a)]
foo = map id . zip

foo' :: [a] -> [a] -> [(a,a)]
foo' a b = map id $ zip a b

但是foo失败并出现以下错误:

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

任何意见将不胜感激。

1 个答案:

答案 0 :(得分:5)

如果查看(.)的定义/类型签名,您会看到它的参数是带有单个参数的函数。但是zip有两个,因此你必须提供至少一个参数才能使它等效

foo a = map id . zip a