<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">&lt;<a href="mailto:tanielsen@gmail.com">tanielsen@gmail.com</a>&gt;</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]-&gt;b)-&gt;[a]-&gt;([a]-&gt;b)<br>
curryWithList f lst1= \lst2 -&gt;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>
&lt;<a href="mailto:lemming@henning-thielemann.de">lemming@henning-thielemann.de</a>&gt; wrote:<br>
&gt;<br>
&gt; On Thu, 7 Aug 2008, Sukit Tretriluxana wrote:<br>
&gt;<br>
&gt;&gt; Dear Haskell experts,<br>
&gt;&gt;<br>
&gt;&gt; I am currently studying Groovy language. An experiment I did with its<br>
&gt;&gt; closure is to perform closure/function &quot;curry&quot; using an array containing the<br>
&gt;&gt; values for the parameter binding. See the sample below.<br>
&gt;&gt;<br>
&gt;&gt; int addThemUp(a,b,c,d,e) { a+b+c+d+e }<br>
&gt;&gt; def arrayCurry(arr, cls) { arr.inject(cls) { c, v -&gt; c.curry(v) } }<br>
&gt;&gt; println addThemUp(1,2,3,4,5)<br>
&gt;&gt; println arrayCurry([1,2,3,4,5], this.&amp;addThemUp)()<br>
&gt;&gt; println arrayCurry([1,2,3,4], this.&amp;addThemUp)(5)<br>
&gt;&gt;<br>
&gt;&gt; The printouts from the above code are the same, verifying that the code<br>
&gt;&gt; works fine. Then I come to ask myself how I can do the same in Haskell. I&#39;m<br>
&gt;&gt; not a Haskell expert so I couldn&#39;t figure it. I wonder if you guys could<br>
&gt;&gt; shed some light on this.<br>
&gt;<br>
&gt; I do not know Groovy, but maybe you want something like<br>
&gt;<br>
&gt; &nbsp;addThemUp :: Num a =&gt; (a,a,a,a,a) -&gt; a<br>
&gt; &nbsp;addThemUp (a,b,c,d,e) = a+b+c+d+e<br>
&gt;<br>
&gt; &nbsp;-- should be better named list5Curry or so<br>
&gt; &nbsp;arrayCurry :: ((a,a,a,a,a) -&gt; a) -&gt; [a] -&gt; a<br>
&gt; &nbsp;arrayCurry cls [a,b,c,d,e] = cls (a,b,c,d,e)<br>
&gt;<br>
&gt; &nbsp;print (addThemUp(1,2,3,4,5::Int))<br>
&gt; &nbsp;print (arrayCurry addThemUp [1,2,3,4,5::Int])<br>
&gt;<br>
&gt; However, it&#39;s hardly of any use, since you won&#39;t use a list if the number<br>
&gt; of elements is fixed (and small) or if the elements even must have<br>
&gt; distinct types.<br>
</div></div>&gt; _______________________________________________<br>
&gt; Haskell-Cafe mailing list<br>
&gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<br>
</blockquote></div><br></div>