<div dir="ltr">Thanks Tom and Henning for your response. Let me put the question in another way by generalizing and tweaking it a little bit.<br><br>How in Haskell that I can create a function that curries <b>any </b>other function, which receives multiple parameters, by using a the input from a list (same data type) or a tuple (mixed data type) such that it either returns another closure (if not all parameters are curried) or the final value of the computation (when all parameters are known)?<br>
<br>Ed<br><br><div class="gmail_quote">On Thu, Aug 7, 2008 at 12:49 PM, Tom Nielsen <span dir="ltr"><<a href="mailto:tanielsen@gmail.com">tanielsen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Maybe you want something like<br>
<br>
curryWithList :: ([a]->b)->[a]->([a]->b)<br>
curryWithList f lst1= \lst2 ->f (lst1++lst2)<br>
<br>
addThemUp = sum<br>
curried = curryWithList addThemUp [1,2,3,4]<br>
curried [5] =15<br>
<div><div></div><div class="Wj3C7c"><br>
On Thu, Aug 7, 2008 at 8:35 PM, Henning Thielemann<br>
<<a href="mailto:lemming@henning-thielemann.de">lemming@henning-thielemann.de</a>> wrote:<br>
><br>
> On Thu, 7 Aug 2008, Sukit Tretriluxana wrote:<br>
><br>
>> Dear Haskell experts,<br>
>><br>
>> I am currently studying Groovy language. An experiment I did with its<br>
>> closure is to perform closure/function "curry" using an array containing the<br>
>> values for the parameter binding. See the sample below.<br>
>><br>
>> int addThemUp(a,b,c,d,e) { a+b+c+d+e }<br>
>> def arrayCurry(arr, cls) { arr.inject(cls) { c, v -> c.curry(v) } }<br>
>> println addThemUp(1,2,3,4,5)<br>
>> println arrayCurry([1,2,3,4,5], this.&addThemUp)()<br>
>> println arrayCurry([1,2,3,4], this.&addThemUp)(5)<br>
>><br>
>> The printouts from the above code are the same, verifying that the code<br>
>> works fine. Then I come to ask myself how I can do the same in Haskell. I'm<br>
>> not a Haskell expert so I couldn't figure it. I wonder if you guys could<br>
>> shed some light on this.<br>
><br>
> I do not know Groovy, but maybe you want something like<br>
><br>
> addThemUp :: Num a => (a,a,a,a,a) -> a<br>
> addThemUp (a,b,c,d,e) = a+b+c+d+e<br>
><br>
> -- should be better named list5Curry or so<br>
> arrayCurry :: ((a,a,a,a,a) -> a) -> [a] -> a<br>
> arrayCurry cls [a,b,c,d,e] = cls (a,b,c,d,e)<br>
><br>
> print (addThemUp(1,2,3,4,5::Int))<br>
> print (arrayCurry addThemUp [1,2,3,4,5::Int])<br>
><br>
> However, it's hardly of any use, since you won't use a list if the number<br>
> of elements is fixed (and small) or if the elements even must have<br>
> distinct types.<br>
</div></div>> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
><br>
</blockquote></div><br></div>