1 is actually an example of partial application of functions more than
it is currying. Haskell's currying makes partial application far more
natural though. In Clojure you can use the (partial ...) macro to do
this:

user=> (def f (partial + 1))
user=> (f 1)
2

2 is done using the (fn ...) special form. It should be noted that
(defn ...) to define named functions is actually just a macro that
translates basically to (def name (fn ...))

user=> (def f2 (fn [x] (* x 2)))
user=> (f2 2)
4

3 is done with the (comp ...) macro:

user=> ((comp f2 f) 3)
8

Hope this helped!

Matt

On Nov 24, 5:54 pm, dokondr <[EMAIL PROTECTED]> wrote:
> How can I write the following examples in Clojure that in Haskell will
> be:
>
> --  1) Curried function:
> Prelude> let f = (+) 1
> Prelude> f 1
> 2
>
> -- 2) Anonymous function:
> Prelude> let f2 = \x -> x * 2
> Prelude> f2 2
> 4
>
> -- 3) Function composition:
> Prelude> (f2 . f) 3
> 8
> Prelude>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to