Re:Functional Programming Jargon
by masklinn on Tuesday November 07, 2017 @10:52AM
(#15644389)
> Currying as an example, I'm none the wiser as to why it's a preferable way of composing a function and it's arguments, or when either is applicable.
The primary advantage of curried functions is that they're trivially partially applicable.
With an uncurried function, if you have a function of two arguments and you want to apply the first but "hold off" on the second you have to wrap the thing in a new function with a single argument which will do the application later (the language may also provide a helper) whereas with curried functions, you can just apply one of the parameters:
let add5 = (a) => a.map((n) => n + 5)
versus
let add5 = map (\n -> n + 5)
This means you can very easily create "small specialisations" of very generic functions.
Languages with curried functions also tend to provide features like the ability to treat operators as functions ("sections"):
The primary advantage of curried functions is that they're trivially partially applicable.
With an uncurried function, if you have a function of two arguments and you want to apply the first but "hold off" on the second you have to wrap the thing in a new function with a single argument which will do the application later (the language may also provide a helper) whereas with curried functions, you can just apply one of the parameters:
versus This means you can very easily create "small specialisations" of very generic functions.Languages with curried functions also tend to provide features like the ability to treat operators as functions ("sections"):
and more function composition tooling: though these are not really intrinsic.