简体   繁体   English

哈斯克尔 - 关于咖喱

[英]Haskell - About Curried

In Haskell all functions are originally curried, right? 在Haskell中,所有功能都是最初的咖喱,对吗?

So, let's look at the max function, and I'll write what I understand about how this works. 那么,让我们看一下max函数,然后我将写下我对其工作原理的理解。

When I write something like this: 当我写这样的东西时:

max 4 5

What happens is that a new funcion is created that internally has value of 4, which then recieves a value, so this function is applied to 5 and a correct value is returned? 会发生的是创建一个内部值为4的新函数,然后接收一个值,因此将此函数应用于5并返回正确的值?

Did I say something wrong somehow or is this correct? 我是以某种方式说错了还是这是正确的?

That's correct. 那是对的。 You can remember what currying is all about by memorizing two of its most important identities: 通过记住两个最重要的身份,你可以记住什么是currying:

-- Function type right-associativity:
a -> b -> c = a -> (b -> c)

-- Function application left-associativity:
f x y = (f x) y

These two identities work together and produce a curried language. 这两种身份共同发挥作用,产生一种讨厌的语言。

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

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