On Sun, Oct 2, 2011 at 4:18 AM, Chaddaï Fouché <chaddai.fouche@gmail.com> wrote:
On Sat, Oct 1, 2011 at 2:40 PM, Petar Radosevic <petar@wunki.org> wrote:
> Peter Hall wrote the following on Sat, Oct 01, 2011 at 10:49:31AM +0100:
>> I think this sentence isn't right:
>>
>> "Curried functions are functions that only take one parameter."
>>
>> The way I understand it, a non-curried function takes only one
>> parameter. Currying is syntactic sugar so you don't have to use
>> higher-order functions every time you want multiple parameters.
>>
>> Without currying, if you wanted a function like:
>>
>>     f a b c = 2 * a + b - c
>>
>> , you'd have to write it something like:
>>
>>   f a = f1
>>       where f1 b = f2
>>           where f2 c = 2 * a + b - c
>>
>> or
>>
>>    f a = (\b -> (\c ->  2*a + b -c))
>
> You are right, I changed the sentence to better reflect wat currying
> really is. Thank you for your input.

Sorry but you are mistaken on the sense of currying. Basically to
curry the function f is to transform it from the type "(a,b) -> c" to
the type "a -> (b -> c)", in other words instead of function from a
cartesian product to a set, you get a function from the first element
of the product to the set of function from the second element of the
product to the original final set. This is a mathematical
transformation that Curry noted was always possible whatever the
function.
In a CS context, this transformation is only possible in languages
that handle functions as first-class data types, Haskell (or the ML
family) is only special in that it encourage you to write every
functions in an already curried style instead of the uncurried fashion
that is used in most other languages. Every single example you give in
your blog is curried, uncurried would be :

> sumTwo :: (Int,Int) -> Int
> sumTwo (x,y) = x + y

and

> f :: (Int,Int,Int) -> Int
> f (a,b,c) = 2 * a + b - c


How would you classify a function of type (Int, Int) -> Int -> Int ?
Likewise if we have a polymorphic foo: Int -> a and we instantiate a to Int -> Int  does foo suddenly get curried?

Which is why it may be better to say this?
Curried and uncurried function are vague ideas, whereas the action of currying and uncurrying -- as embodied in the standard prelude curry and uncurry -- are precise and well-defined

See the function "curry" and "uncurry" to see that passing from one
style to another can be automated (though only elegantly for two
parameters).

Still it is true that currying functions ease the partial application
of function (at least if your parameters are ordered sensibly).

--
Jedaï

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners