Created
October 15, 2012 08:24
-
-
Save anonymous/3891431 to your computer and use it in GitHub Desktop.
note on currying...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;From solutions/continuation-passing.clj - ex 2: | |
;; By the way, the decomposition of '(a b c) is closer to the real | |
;; definition of currying, which (in its technical rather than | |
;; colloquial sense) is about representing a function with multiple | |
;; arguments as multiple composed functions with one argument. In some | |
;; functional languages, notably Haskell, all functions are | |
;; curried. That is, if you had a function `plus` that added two | |
;; arguments, it's *really* a function that takes one argument and | |
;; yields a function that takes one argument. Here's an example: | |
;; | |
;; This defines the function `plus`: | |
;; | |
;; Prelude> let plus a b = a + b | |
;; | |
;; It can take two arguments: | |
;; | |
;; Prelude> plus 1 2 | |
;; 3 | |
;; | |
;; You don't have to use something like `partial` to make a one-argument | |
;; incrementor. Instead, `plus` with one argument *is* a one argument | |
;; function: | |
;; | |
;; Prelude> let increment = plus 1 | |
;; | |
;; Prelude> increment 300 | |
;; 301 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment