Jump to content

Talk:Currying: Difference between revisions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Content deleted Content added
BotPuppet (talk | contribs)
m BOT: substituting template per WP:SUBST, Replaced: {unsigned → {subst:unsigned
Line 153: Line 153:
: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'"?
: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'"?
:--[[User:Manifolds|manifolds]] 10:50, 25 May 2007 (UTC)
:--[[User:Manifolds|manifolds]] 10:50, 25 May 2007 (UTC)

== Structure missing ==


"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

Revision as of 18:03, 18 August 2009

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)[reply]

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)[reply]

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)[reply]

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)[reply]
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)[reply]
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)[reply]
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)[reply]

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)[reply]

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)[reply]

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)[reply]

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)[reply]

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 (talkcontribs)

Why the Perl6 example was suppressed?

Spayrard 23:35, 18 September 2006 (UTC)[reply]

Perhaps because it was not really an example of currying? --LambiamTalk 13:08, 19 September 2006 (UTC)[reply]

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)[reply]

Python introduced closures in 2001, as part of the 2.1 release; see PEP 227. --Piet Delport 08:53, 6 February 2007 (UTC)[reply]

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).[reply]

Yes, somebody please cleanup the text. The "simply put", isn't. --Belg4mit 22:30, 9 April 2007 (UTC)[reply]

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)[reply]

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)[reply]

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)[reply]

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)[reply]

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)[reply]

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)[reply]
I went ahead and did it anyway --Belg4mit 22:27, 9 April 2007 (UTC)[reply]

Profusion of examples

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)[reply]

I changed the C# example to use LINQ - hope this is okay Pdhooper 21:32, 9 May 2007 (UTC)[reply]

My preference/suggestion is: ==>

  1. 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)!!!
  2. 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)[reply]

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)[reply]

Currying != Generalized Partial Application

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)[reply]

Structure missing

"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