简体   繁体   English

Haskell:无点样式

[英]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 : 我希望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

But foo fails with following error: 但是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

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 但是zip有两个,因此您必须提供至少一个参数以使其等效

foo a = map id . zip a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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