简体   繁体   English

haskell中组成的arguments的数量

[英]Number of arguments of composition in haskell

Recently I have been learning about compositions in haskell and am now a bit confused concerning this example.最近我一直在学习 haskell 中的组合,现在对这个例子有点困惑。

(const . min) 3 0 4

As a result I get 3, so internally it must be computed like:结果我得到 3,所以在内部它必须像这样计算:

const (min 3) 0 4

But I thought since min takes two arguments, it should look like this:但我想既然 min 需要两个 arguments,它应该是这样的:

const (min 3 0) 4

So apparently the composition only takes this one argument, in this case 3, instead of all the arguments for min like I expected it to.因此,显然该组合只采用了这一论点,在这种情况下为 3,而不是像我预期的那样,所有的 arguments 都是最小的。 Does that mean compositions only take one argument per default or what am I not getting here?这是否意味着作品在默认情况下只接受一个参数,或者我在这里没有得到什么?

You can answer your question by manually evaluating the initial expression.您可以通过手动评估初始表达式来回答您的问题。

(const . min) 3 0 4
⇒ (\x -> const (min x)) 3 0 4    * defn of (.)
⇒ (const (min 3)) 0 4            * function application
⇒ ((\x y -> x) (min 3)) 0 4      * defn of const
⇒ (\y -> min 3) 0 4              * function application
⇒ (min 3) 4                      * function application
⇒ 3                              * because 3 is less than 4

It is worth noting that function application is left-associative, so, fxy means the same as (fx) y .值得注意的是 function 应用程序是左关联的,因此fxy(fx) y的含义相同。

It is also worth noting that \xy -> z means the same as \x -> \y -> z .还值得注意的是\xy -> z\x -> \y -> z z 的含义相同。

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

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