Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As an aside, if you just want curried functions in Clojure, try poppea.

https://github.com/JulianBirch/poppea



Noob question, doesn't partial provides curried functions?


A 'true' curried function in clojure doesn't need partial because it overloads on the arity of the function. It automatically partializes itself if it's called with too few arguments.

E.g. you have a function f that takes two arguments, x and y. If the function is truly curried, then (f x y) is a full function call of f that returns a value, while (f x) returns a function of one argument, as if you had used partial. You could create a (two-argument) currying helper-function with the following:

  (defn curry-2 [f]
        (fn ([x] (partial f x))
            ([x y] (f x y))))
Basically with a currying function, (f x y) and ((f x) y) are equivalent calls, without the need for partial.

The reason this isn't more pervasive is because it doesn't play well with optional parameters, &rest parameters, arity overloading, or other ways in which the number of arguments to a function might vary (Haskell permits currying by not allowing variable param lists). Clojure has a couple of library functions that use this pattern (notably, the reducer library), but it's not ubiquitous.


Indeed, that's exactly what poppea does. The code is a generalisation of the code in the reducers library.


Partial application and curried functions are subtly different.

Consider a "+" operator that does currying:

    ((+ 5) 10)
If the plus operator is not currying, that's either an arity or type error. You're either not supplying enough arguments to +, or you're trying to do this:

    (5 10)
Partial application can be explicit, without currying:

    ((partial + 5) 10)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: