Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell - About Curried

Tags:

haskell

In Haskell all functions are originally curried, right?

So, let's look at the max function, and I'll write what I understand about how this works.

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?

Did I say something wrong somehow or is this correct?

like image 327
Édipo Féderle Avatar asked Sep 27 '12 02:09

Édipo Féderle


People also ask

What does Uncurry do Haskell?

uncurry converts a curried function to a function on pairs. All it does is it takes a function (a -> b -> c) and returns a function that takes the parameters as a tuple.

How do you write a curry function?

The following basic example uses currying. function multiply(a, b, c) { return a * b * c; } function multiply_curried(a) { return function (b) { return function (c) { return a * b * c } } } let res = multiply(1, 2, 3); console. log(res); let mc1 = multiply_curried(1); let mc2 = mc1(2); let res2 = mc2(3); console.

What is the difference between currying and partial application?

Simple answer. Currying: Lets you call a function, splitting it in multiple calls, providing one argument per-call. Partial Application: Lets you call a function, splitting it in multiple calls, providing multiple arguments per-call.

Who was Haskell?

Charles Nathaniel Haskell (March 13, 1860 – July 5, 1933) was an American lawyer, oilman, and politician who was the first governor of Oklahoma.


1 Answers

That's correct. You can remember what currying is all about by memorizing two of its most important identities:

-- 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.

like image 115
ertes Avatar answered Sep 24 '22 22:09

ertes