Haskell:无点风格

Chu*_*ang 0 haskell pointfree

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

我期望foo并且foo'是等价的,也就是说,foo'它只是一个无点函数foo:

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

foo' :: [a] -> [a] -> [(a,a)]
foo' a b = map id $ zip a b
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

任何意见将不胜感激.

eps*_*lbe 5

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

foo a = map id . zip a
Run Code Online (Sandbox Code Playgroud)

  • 啊哈.我可以看到.然后`map`拒绝函数参数. (2认同)