3 ms·
Awesome job! I was trying to understand curry by learning Haskell but you summed it up perfectly. What is the difference between curry and partial? Is a partia
by ripter 12y ago
Awesome job! I was trying to understand curry by learning Haskell but you summed it up perfectly.
What is the difference between curry and partial? Is a partial just a curry that hasn't filled in all the arguments yet?
- chriswarbo 12y agoI assume you mean "partial application"? "Currying" turns a multi-argument function into a chain of one-at-a-time wrappers. If we curry a 5-argument function "foo(a, b, c, d, e)", we get a nesting of 5 functions, each accepting one argument "foo(a)(b)(c)(d)(e)". The implementation in the article, as well as my own, go slightly further and also allow curried functions to accept multiple arguments at once, eg. "foo(a, b, c, d, e)"; this is just for convenience though, a "real" curried function must accept arguments one at a time. Note that in Haskell syntax, there is no difference between the two: "foo a b c d e". Alternatively, "partial application" takes some argument values now, returning a function which accepts the rest later. If we partially-apply a 5-argument function with, say, its first 2 arguments, we get back a 3-argument function, eg. "papply(foo, a, b)(c, d, e)". Note that we must use partial application explicitly whenever we want to supply a few more arguments; curried functions keep track of this themselves. As an aside, you mention Haskell. Note that Haskell functions are already curried; in Haskell, "curry" and "uncurry" convert between functions which accept separate arguments and functions which accept one big tuple of arguments.
- chc 12y agoAs it exists in Haskell, yes, that's what partial application is — the result of applying a curried function to less than the full number of arguments. Some other languages have a more general form of partial application where you can partially apply arguments in non-sequential order, which isn't related to currying and instead just means creating a wrapper function that calls the original function with certain arguments filled in.