I think this, along with the whole article, is the best explanation of currying I've seen on the whole damn internet.
I think this, along with the whole article, is the best explanation of currying I've seen on the whole damn internet.
http://www.uncarved.com/blog/not_currying.mrk
Which the author freely admits:
(Some will insist that what we're doing is more properly called "partial application", and that "currying" should be reserved for the cases where the resulting functions take one parameter, each resolving to a separate new function until all the required parameters have been supplied. They can please feel free to keep on insisting.)
-- all morally identical
a -> b -> c -> d
a -> (b -> c -> d)
a -> (b -> (c -> d))
(a, b) -> c -> d
(a, b, c) -> d
((a, b), c) -> d
(a, (b, c)) -> d
However, so long as you have parameter order (we're not allowed to commute our tuples, just reassociate nested tuples like ((a, b), c) <-> (a, (b, c)) and so on) then flip still morally works flip (someFn :: (a, b, c) -> d)
:: (b, a, c) -> d
:: (b, a) -> c -> d
:: b -> a -> (c -> d)
The same story holds for partial evaluation. Of course, there have to be far more edge cases to handle all this tuple twiddling.---
Really, I think it's pretty meaningful to blur the distinction between "curry (once)" and "curry repeatedly along with tuple reassociation". The later forms an equivalence class of function types which all have the same application behavior.
(a, b) -> c
are exactly equivalent to the things of type a -> (b -> c)
An adjunction (F, G) occurs when the things of type (F a -> c) are equivalent to things of type (a -> G c), so if we pick F x = (x, b) and G x = (b -> x) then we see that currying is an adjunction between (,b) and (b ->).I feel that although the distinction can be very important, it's much less so for Javascript. And the implementation in Ramda can be used that way any time you choose:
var total = reduce(add)(0); // or
var sum = reduce(add)(0)(numbers)
works just as well in Ramda as var total = reduce(add, 0); // or
var sum = reduce(add, 0, numbers)
So, as I said, feel free to keep on insisting. :-)Start at 26mins. You don't have flip. You lose control over partial application. It isn't curry. You're right. It is an important distinction :)