Talk:Currying
From Wikipedia, the free encyclopedia
Contents |
[edit] Untitled
- To do: How about a practical example for currying helping to formulate clearer code? "What is it good for?" --84.114.179.138 17:30, 13 May 2006 (UTC)
the utility is only clear once you've worked with functional languages for a bit. nearly everyone, in almost every language, eventually curries (by my contentious and broad definition), but it is more clear, and more fundamental, when you move to (positive adjective) languages.
- To Do: Good idea. It is very useful for list manipulation. I may slice off my C# example and give a real application ((('a * 'b) -> 'b) -> 'b -> 'a list -> 'b function applied to lists), but I'm not sure how much space it would deserve.
- To Do: Link to the article about Foldr (and by extension foldl) perhaps? It is very common that you have a list of things that you want to turn into one big thing before outputting it. Here the functions foldr and foldl (Haskell and ML names) come in very handy for example in ML you can do
val sumList = foldr op+ 0
to get a function sumList that takes a list of integers and returns the sum of its elements. In other words, currying for the sake of currying is not very useful (though it may have some theoretical niceties such as it being possible to consider all functions as unary). You could even argue that all it does is save you a couple of parentheses.
- To do: Add Scheme language definition for currying to any given depth.
(moved from the article -- Timwi 22:20 19 Jun 2003 (UTC))
- To do: Add note that C++ is evolving the ability to curry functions via template libraries such as the Boost Libraries.
[edit] Schönfinkelisation
Who calls currying Schönfinkelisation? I see the link, but it is rather unhelpfdiaul, unless I want to buy the book. Google has three hits for Schönfinkelisation, two of which are this page, and one of which is a PDF in French that claims it is called Schönfinkelisation in Europe. I've spent some time in the UK, and they call it currying there. Is it just called Schönfinkelisation in France? Jm307 17:09, 22 August 2006 (UTC)
- Not on the French Wikipédia; they only have Curryfication. I never heard the term "Schönfinkelisation" on any continent. It may be that that term has some currency among logicians, while "Currying" is for programmers. --LambiamTalk 18:25, 22 August 2006 (UTC)
-
- I forgot about this! So, is this just one of those "we'll take it on faith" things? Jm307 20:55, 15 November 2006 (UTC)
[edit] Is the c++ example bogus?
I think the c++ example is bogus. It is true that plus_one(2) does get you 3, but you can't pass plus_one to functions that take a function pointer as an argument. In other words, it's not a real function; it just looks like one when you call it in certain ways. Maw 00:12, 3 August 2006 (UTC)
- Define "function pointer". C++ is notable in that it can do everything - it can have real functions, with a statically defined pointer, that can be pointed to by C code and template-free C++ code, and it can have abstract functor objects to which any sort of computability-theoric transformation can be applied. By fully applying all the abstractions provided by the standard library alone (not counting the countless others provided by libraries like Boost), C++ can turn into another language altogether.
It's not real currying - agreed. It's just a class that takes an integer parameter in its constructor and has another function to add that integer to an extra parameter.. Dastle 05:03, 14 October 2006 (UTC)
- If it's bogus we should not keep it. Therefore I've removed it. In general, let us agree that a language supports currying if in that language you can define some higher-order operation CURRY that, applied to some f : (X × Y) → Z, produces CURRY(f) : X → (Y → Z). The fact that in language FOO you can define both f : (X × Y) → Z and g : X → (Y → Z) does not already mean FOO supports currying. --LambiamTalk 13:06, 12 November 2006 (UTC)
[edit] Why the Perl6 example was suppressed?
Spayrard 23:35, 18 September 2006 (UTC)
- Perhaps because it was not really an example of currying? --LambiamTalk 13:08, 19 September 2006 (UTC)
[edit] Does Python support closures?
My understanding is that python doesn't support closures, so its presence in the list is incorrect 202.183.101.128 02:06, 7 January 2007 (UTC)
- Python introduced closures in 2001, as part of the 2.1 release; see PEP 227. --Piet Delport 08:53, 6 February 2007 (UTC)
[edit] comprehensibility
The first half of the introduction (which put me off the rest until I decided to leave a note asking WTF it's good for and decided to double-check) and most examples is gobbledygook. The ML example was the most instructive, and I don't even know ML. One possible means of clarifying things (besides getting to the point early) is to describe currying as a factory for functions. It may also be necessary to separate the math from the programming for clarity. —The preceding unsigned comment was added by 155.212.241.202 (talk) 17:16, 27 February 2007 (UTC).
[edit] Scheme
Why can we not give an easier example for currying in scheme? Like
;;add:number->(number->number) ;;Adding using currying (define (add x) (λ(y) (+ x y))) >((add 10) 10) 20 I am new to scheme and I found the example not much helpful.
I changed it. Comments on it please. ~rAGU
I updated it to match its description (e.g. a general currying function). I am not sure that this example is more readable or easier but it seems more conceptually aligned with scheme. Jaimico 14:36, 28 March 2007 (UTC)
[edit] Sorted list
I've alphabetized the list of examples (which btw is far too long). Feel free to un-alphabetize it, but do apply /some/ order to the list. Alternative: nuke it. It's long and useless. Keep the Scheme example or such, as it does a good enough job of explaining what the concept is. -- vstarre
- Reverted, the previous order was not random but rather functional languages (currying's origins) first, then ~alphabetic (people have been adding/moving things to break that). I personally never explicitly labeled the break as you could only say "functional/non-functional," and even then many languages cannot be clearly pigeonholed. --Belg4mit 00:40, 7 April 2007 (UTC)