Talk:Currying
This article is rated C-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Untitled
[edit]- To do: Disambiguation to distinguish this term from caring for a horse and from currying favor. — Preceding unsigned comment added by Pdesousa (talk • contribs) 17:40, 31 March 2011 (UTC)
- 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.
- It already has the ability. Overloaded constructors and operator() does exactly what currying does. KayEss | talk 05:56, 2 August 2006 (UTC)
Schönfinkelisation
[edit]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)
- Googling for
[Schönfinkelisation OR Schönfinkelization]
gives 54 hits, many of which can be connected to the Heim & Kratzer textbook. --LambiamTalk 00:26, 16 November 2006 (UTC)
- Googling for
- Right. This is the context I learned it in (logic/semantics). My instructor was Hungarian, for what its worth.AftonLewis (talk) 17:59, 15 September 2009 (UTC)
- The term just isn't in common use. I've taken the liberty of currying the lead section. --Tony Sidaway 00:59, 31 August 2007 (UTC)
- Function schönfinkeling... yeah right! If anything this mention is a bit funny, and if it's factually correct (which I'm assuming it is), then I'm for keeping it. — Preceding unsigned comment added by 178.135.120.222 (talk) 15:33, 29 October 2011 (UTC)
Is the c++ example bogus?
[edit]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)
I've created a true example of currying in C++ using one of the provided arithmetic functors. is everyone happy with it? Rob.desbois 09:42, 17 April 2007 (UTC)
This is an example of partial application not currying, boost phoenix has currying support but the binders (both standard library and boost::(lambda)::bind) are not examples of currying. This page seems to confuse the matter of partial application and currying. —Preceding unsigned comment added by 217.37.49.212 (talk • contribs)
Why the Perl6 example was suppressed?
[edit]Spayrard 23:35, 18 September 2006 (UTC)
- Perhaps because it was not really an example of currying? --LambiamTalk 13:08, 19 September 2006 (UTC)
Does Python support closures?
[edit]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)
Comprehensibility
[edit]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).
- Yes, somebody please cleanup the text. The "simply put", isn't. --Belg4mit 22:30, 9 April 2007 (UTC)
Scheme
[edit]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)
Is the example given sufficiently similar to LISP that the example ought to be titled for both? Most Schemers/LISPy people are certainly aware of the relation between the two, but other readers might not be? --Belg4mit 22:29, 9 April 2007 (UTC)
I am not sure if this is close enough to Lisp in that this is one of the key divergences between (Common) Lisp and Scheme (split or single name spaces for functions and variables). If you want to curry in Common Lisp with functions (versus macros) is looks like this example from sourceforge. I find them rather different different.Jaimico 07:48, 11 April 2007 (UTC)
Dear Jaimico, Thank you for explaining. But I feel the simpler and specific examples make the concept clear. Examples should require no or little scheme understanding to understand. I am thinking that adding constructs like 'f . arg' and 'append' make it less intuitive. ? ~rAGU
Greetings Raguks. I see and agree with your point. At the same time, it seems to me that there is a rather significant difference between a function that returns functions (as say the example in Python) and a function (functor) that maps arbitrary (functions, arguments) pairs into functions (as the example in Haskell). I am not sure that it would not have occurred to me to call the former currying. In any case, it is not clear cut: the Java example is in the middle of the two. It is now a general currying function (thus highlighting a possibility in the language) but perhaps "simple" has suffered. I added a short explanation following the Eiffel and Haskell examples. Does this help or make it worse?
Also, is it obvious that "examples should require little/no understanding of the language in which they are written"? It is not perfectly clear what the point of having code examples is. I see two possibilities. The first is to allow people to read an example in a language in which they are versant (in which case an assumption of familiarity is reasonable). The second is to highlight different capabilities and features of different languages (in which case simplicity needs be balanced against language expression).
I fear this is getting long-winded so I will thank you for the useful discussion and wait a bit. Jaimico 10:06, 8 May 2007 (UTC)
As per the discussion beneath "Currying != Generalized Partial Application", I updated the function to be curry (versus curry + evaluate). The discussion at LtU linked to is worth reading.Jaimico 12:57, 29 May 2007 (UTC)
Sorted list
[edit]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)
- I went ahead and did it anyway --Belg4mit 22:27, 9 April 2007 (UTC)
Profusion of examples
[edit]I think we have enough examples, and probably don't need more. As it is, I'm tempted to remove the Io one. How relevant of a lanuage is this?? I'd also probably remove the Java instance because of it's sheer verbosity escept for the popularity of Java, and the fact that the keen observor will then recognize that some metaphors work well in some languages, and not so much in others. --Belg4mit 22:33, 9 April 2007 (UTC)
- I changed the C# example to use LINQ - hope this is okay Pdhooper 21:32, 9 May 2007 (UTC)
My preference/suggestion is: ==>
- Sort the examples by time, in a timeline - This demonstrats any evolution, deviations (and/or popularity shifts) in the concept.
- Keep atleast one example per decade
- 1950s, 1960s, 1970s etc
- Keep examples that demonstrate some kind of historic innovation.
- Keep examples that are famously short, or bad or in some other way notable. (e.g. Check out python's 3-line quick-sort)!!!
- Keep atleast one example per decade
- Then where the concept has simply (and faithfully) been transmorgrified into a newer language, move the decendent example into Wikibooks. Eg for currying
we can use the URL: http://en.wikibooks.org/wiki/Algorithm_implementation/Miscellaneous.
I find the examples in other languages especially useful - currying being a very good example - because I can quickly see if the languages supports the feature, and if there are "issues" in using the feature in the new language I am learning. Hence IMHO these examples should be retained in wikibooks.
The first example I saw of this approach was with Quicksort: ==>
This approach seems to work well.
NevilleDNZ 08:21, 10 May 2007 (UTC)
Yes, these examples must go: it's fine to incorporate illustrative examples into the narrative, but Wikipedia is not an indiscriminate list or guide. (I'm not sure if Algorithm implementation exactly is the best place to put it (this is a technique, not so much an algorithm), but definitely somewhere on Wikibooks should be fine.)
As it stands, i don't think anything in the Examples section contributes significantly to article, so i'm going to be bold and drop it wholesale. The history can be used to port it to Wikibooks, or wherever. --Piet Delport 00:04, 3 July 2007 (UTC)
Interesting example of being bold. NevilleDNZ (talk) 11:20, 2 April 2013 (UTC)
Currying != Generalized Partial Application
[edit]As noted in
http://lambda-the-ultimate.org/node/2266
and
http://srfi.schemers.org/srfi-26/mail-archive/msg00000.html
Currying != Generalized Partial Application
—The preceding unsigned comment was added by 82.203.170.156 (talk) 19:23, 24 May 2007
- As the article's history shows, many people confuse the two. I was one of them until I read your links. Before that, I thought you were all being terribly pedantic.
- However, in many cases (for programming, at least), the two are trivially equivalent. Thus, the term will likely continue to be generally "misused". Perhaps it would be best to create an entry for "partial application", and add a link to the top of the currying page along the lines of "In computer programming, currying is often generalized to mean 'partial application'"?
- --manifolds 10:50, 25 May 2007 (UTC)
--- This section should be removed entirely. It is based on the ranting of two non-authoritative sources and doesn't express anything meaningful. Was very tempted to wholesale just delete this section lacking the energy to re-write it into something of any potential educational value. — Preceding unsigned comment added by 174.61.151.97 (talk) 23:19, 16 October 2021 (UTC)
Structure missing
[edit]"When viewed in a set-theoretic light, currying becomes the theorem that the set of functions from to A, and the set (AB)C of functions from C to the set of functions from B to A, are isomorphic."
This sentence means nothing. Two structures are isomorphic but not two sets. So the structure here is missing. -- fl
- I noticed this as well. I fixed it so it's not as confusing, but I'm still not positive the idea is properly conveyed. Wgunther (talk) 22:00, 22 July 2010 (UTC)
Missing Link
[edit]Reference 1, the reference to the mysterious Schönfinkel, seems to lead nowhere.
Also, this article says that Curry "re-invented" the concept, presumably independently, whereas the article on Schönfinkel says "While Curry attributed the concept to Schönfinkel, it had already been used by Frege." Which is it? Mhkay (talk) 21:03, 19 August 2009 (UTC)
Programming language in Motivation section
[edit]I've just semi-rewritten the Motivation section for WP:STYLE. The code examples look a bit off to me, but I don't recognize the language so I could be wrong (and if I'm not, I wouldn't know what to change it to). Specifically, why does this language have seemingly random rules for parenthesis placement around function arguments? --Scgtrp (talk) 04:55, 28 June 2010 (UTC)
- I'm also curious what language this is. I'm going guess it's pseudocode because of how simple the function assignment is. It's not even that simple in symbolic math languages, like Mathematica. If you're going to make it pseudocode, you should probably just write it in lambda expressions which will probably be easier to read. It would be nice to see an example in some real programming language since this is otherwise a very theoretical article, but I feel like the language should be Haskell, Scheme, ML, or LISP since those are the more popular functional languages. Maybe I'm just delusional and it's a real language? Wgunther (talk) 22:24, 22 July 2010 (UTC)
- It was pretty much Haskell, with some superfluous or even wrong pairs of parentheses. I've now reinstated a correct version of the code. --Daniel5Ko (talk) 16:31, 12 March 2011 (UTC)
Also invented by Gottlob Frege?
[edit]According to the German Wikipedia, Currying was also invented by Gottlob Frege. Does anybody have further information? 79.230.171.86 (talk) 09:02, 31 July 2011 (UTC)
Always possible?
[edit]Is it (provably) true that any function can be curried? For example, I'd expect that y = f(a,b) = ((a+b) / (a*b)) could not be curried. — Preceding unsigned comment added by 87.194.171.29 (talk) 23:19, 25 October 2011 (UTC)
- Yes, at least in cases where the functions are not too limited. If I'm not mistaken, taking "function" to mean "morphism in a cartesian closed category" is exactly what is needed. In these cases, the difference is (or can be thought of) almost only in the syntax of function definitions. E.g. the curried version of your f might be specified by . See also
curry
anduncurry
in Haskell's standard library, which are inverses of each other. --Daniel5Ko (talk) 23:57, 25 October 2011 (UTC)
- Yes, any function that would be normally encountered by non-mathematicians can be curried. However, there are monoidal categories which are not closed, e.g. the comma category, e.g. the category of pointed spaces. 67.198.37.16 (talk) 17:47, 25 August 2016 (UTC)
The Java example has a syntax error
[edit]The eclipse compiler gives me: Type mismatch: cannot convert from new CurryingTest.Compute<CurryingTest.Compute,Integer>(){} to CurryingTest.Compute<CurryingTest.Compute<CurryingTest.Compute<Integer,Integer>,Integer>,Integer>
Would you guys correct the example? Otherwise I'd prefer to delete it. Thx. — Preceding unsigned comment added by BostX (talk • contribs) 10:56, 11 January 2012 (UTC)
Confusing notation
[edit]I already know what currying is, and I *still* had trouble figuring out what the notation in our examples is supposed to mean.
"g 2 = \y -> f(2,y)"
It's in no way obvious what the "\y" and "->" symbols mean. Could someone more familiar with this idiom add an explanation of, or a link to an explanation of, these terms?
- That's Haskell notation: the
\
represents a λ (lambda abstraction). - I reworded the sentence before it to "Expressed in Haskell code, [...]", which hopefully makes the example clearer. --Piet Delport (talk) 04:14, 2 April 2012 (UTC)
- I translated the Haskell to mathematical notation and added some explanation; hopefully, it's clearer now. ehird (talk) 18:20, 2 April 2012 (UTC)
Motivation example
[edit]In the example in the motivation example, the function g seems to be defined in two different ways. Near the top, it is defined as . Then later it is defined as . So in the first case is a function of the variable that returns a value, and in the second case it is a function of the variable that returns a function. I think. I could be wrong, but either way it would be nice if more clarification was provided as to why these seem to be different. — Preceding unsigned comment added by Richierocks (talk • contribs) 08:17, 13 September 2012 (UTC)
- I think I fixed this example yesterday. 67.198.37.16 (talk) 17:39, 25 August 2016 (UTC)
Mention of motivation missing in Motivation section
[edit]It's great that this article has a "motivation" section. More articles should have such a section. Very few Wikipedia articles take the trouble to discuss why a thing was created, and without that context it can often be impossible for the reader to comprehend what the thing is, since the raw factual information about the thing's structure is meaningless if you don't know what the thing is for.
- Ha! exactly what I have just written. I should have read this first. — Preceding unsigned comment added by 86.182.249.22 (talk) 11:57, 27 November 2014 (UTC)
I see that at some point in this article's history it contained a line that began "The practical motivation for currying is ...", but no language of that form is currently present in the Motivation section, and the motivation section in fact has devolved to the point where it just contains blank factual information about the technical aspects of currying, and no discussion whatsoever about the likely human purposes for organising functions in this way.
I'd fix this myself, if I knew what currying was. Having read the article, I find that I still don't. 81.131.48.185 (talk) 15:02, 19 March 2013 (UTC)
- My mistake, the line about practical motivation is still present. For some reason it is the last line in the article (I admit I gave up before I got that far). I'm moving it to the motivation section. Could do with a little elaboration, I think. 81.131.48.185 (talk) 15:06, 19 March 2013 (UTC)
- Wait, no, the line in its present incarnation is about "partial application". I'd better leave it where it is. So my point stands. 81.131.48.185 (talk) 15:08, 19 March 2013 (UTC)
- The section name is probably not the best. It's mostly an illustrative example rather than the motivation for the concept. As it is, I don't think the example is bad; I do think it illustrates the idea of Currying. It could be improved, however. Also, there's a big fuss made the article about the difference between Currying and partial application which more than likely detracts from a layperson's understanding. The fuss is mostly isolated, but the fact it spills over to a motivating example is not really necessary. Wgunther (talk) 18:51, 19 March 2013 (UTC)
- Consider writing a section which describes the motivation for the concept, please. 213.122.8.41 (talk) 00:49, 27 August 2013 (UTC)
Clueless
[edit]I have read this article, and I have no clue *why* currying is performed.
It's like never having seen a triangle and reading a detailed explanation of Pythagoras' theorem, without any explanation that it allows you to compute the length of the hypotenuse of a triangle.
JavaScript Example
[edit]If I understand the first example on the page correctly, it corresponds to the following JavaScript:
(function(x){ return function(y) { return y/x; } })(2)(3)
XWolfRH (talk) 18:47, 27 October 2015 (UTC)
Source for "coined by Christopher Strachey in 1967"
[edit]I cannot find the word "Currying" in Strachey's 1967 paper. Where is the information source that he coined the term? (Sorry if I'm not following any convention in Wikipedia - I'm not used to editing it and don't have much time to search.) Esumii (talk) 02:47, 6 January 2016 (UTC)
- Yeah, Strachey's Fundamental Concepts in Programming Languages only says:
"There is a device originated by Schönfinkel, for reducing operators with several operands to the successive application of single operand operators."
- The earliest usage of the term that I know of is in Reynolds' "Definitional Interpreters for Higher-Order Programming Languages" (1972):
"In the last line we have used a trick called Currying (after the logician H. Curry) to solve the problem of introducing a binary operation into a language where all functions must accept a single argument. (The referee comments that although "Currying" is tastier, "Schönfinkeling” might be more accurate.)"
- Although it's not entirely clear from that passage if Reynolds coined the term there, or if it was already in use at the time. If the term "currying" was already in use five years before Reynolds' paper, I'd probably have expected Strachey to call it by that name. Or perhaps the term just didn't cross the Atlantic yet?
- I'd thus either remove that sentence from the article, or replace it with a reference to Reynolds' paper.
- —Ruud 08:26, 6 January 2016 (UTC)
- I found a forum post by David Turner (one of Strachey's students), who says Strachey invented it and it's in the 1967 lecture notes. But of course it's not, so there's some miscommunication. My current hypothesis is that it was coined at the Summer School but not written in the lecture notes. Of course this could be wrong, but it seems to fit the evidence. I've edited the article to reflect this. --Mathnerd314159 (talk) 19:51, 3 March 2022 (UTC)
Major expansion/re-write
[edit]I just concluded a major expansion of the math section, and a re-write of the introductory section, that I hope addresses many of the issues and questions in the talk page up above. I tried hard to be very clear in the motivational example, showing all the work and the details, perhaps being a bit repetitive; but I think that's OK. I also tried to carefully define all of the various notations and symbols used. It could probably be tightened up just a bit more, but I'm starting to go cross-eyed, so can't quite spot these. 67.198.37.16 (talk) 21:40, 24 August 2016 (UTC)
- Thanks! —Ruud 21:46, 24 August 2016 (UTC)
Function spaces Hom
[edit]It is said in the article that "One writes Hom(X,Y) for the set of all functions from X to Y, and uses the notation Y^X to denote the subset of continuous functions". However isn't this the other way around? Assuming the category in which Hom is defined is the category of topological spaces Top, Hom(X,Y) denotes the continuous functions from X to Y and Y^X all possible functions from X to Y. 86.115.221.210 (talk) 19:11, 26 February 2024 (UTC)
- C-Class Computer science articles
- High-importance Computer science articles
- WikiProject Computer science articles
- C-Class mathematics articles
- Mid-priority mathematics articles
- C-Class Computing articles
- Low-importance Computing articles
- C-Class software articles
- Mid-importance software articles
- C-Class software articles of Mid-importance
- All Software articles
- All Computing articles