diff options
Diffstat (limited to 'docs/wiki_src/coding/currying.md')
-rw-r--r-- | docs/wiki_src/coding/currying.md | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/docs/wiki_src/coding/currying.md b/docs/wiki_src/coding/currying.md index d84eb0a..9a8e48d 100644 --- a/docs/wiki_src/coding/currying.md +++ b/docs/wiki_src/coding/currying.md @@ -1,13 +1,29 @@ # Currying -Lambda calculus naturally supports currying -- that is, only partially +Lambda calculus naturally supports currying -- that is, only *partially* applying a function. In fact *any* function can be applied with *any* amount of arguments! In bruijn, currying is a great way to make functions even more elegant. -Partially applying the `mul`{.bruijn} function: +For example, take the negation function: ``` bruijn -six [0 (+3)] (mul (+2)) +# subtracts argument from zero +-‣ [(+0) - 0] ⧗ Number → Number + +# equivalent curried version +-‣ sub (+0) +``` + +Currying is also very useful for higher-order functions. + +Multiplying values in a list by partially applying the `mul`{.bruijn} +function: + +``` bruijn +# doubles numbers in a list +double-list [0 <$> (mul (+2))] ⧗ (List Number) → (List Number) + +:test (double-list ((+1) : {}(+2))) ((+2) : {}(+4)) ``` |