Skip to content

Comment on Programming languages to watch: LiveScript, Julia, Elixir

Comments

What this article calls currying is actually partial application.

Partial application is a technique where you take a function that requires n arguments, pass in the first one and get a function that needs n-1 arguments.

Currying is a technique where you take a function that takes n arguments and turn it into a function that can be partially applied. E.g. in Haskell it works with tuples as arguments. There is function 'curry :: ((a, b) -> c) -> (a -> b -> c)' and its counterpart 'uncurry :: (a -> b -> c) -> ((a, b) -> c)'.

You get a function that can take N arguments and return a value, or 1 to N-1 arguments and return a function representing a partial application, which itself exhibits the same behavior:

   add3 = (a, b, c) --> a + b + c

   x = add3 1
   y = x 1
   z = y 1 # z = 3
If you look at the compiled code, it is actually an abstraction over a partial application, but at that point is that not just an implementation detail?

I agree it is not really important.

The main difference between the two I see is that partial application basically binds a certain argument to a fixed value, while currying only changes the way the function is called (thus allowing for easier partial application). It is easier to see on a function with more than two arguments. Imagine f:(A×B×C)->D. Currying it will yield f':A->(B->(C->D)), so you would call it as f'(1)(2)(3). On the other hand, partially applying on first argument it would yield f'':(B×C)->D.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.