Mission: To take args from a list... generally

Joel Koerwer wrote:
Let's say I want to evaluate a function of type (a->a->...->a->a), taking the arguments from a list. If know the function ahead of time, I can simply wrap it:
foo a b c d = ... wrapFoo (a:b:c:d:_) = foo a b c d
But, as an exercise, I challenged myself to write a function, multApply :: (a->a->...->a->a) -> [a] -> a, that automatically does the wrapping for any such function.
This came up a while ago (but with a list of functions of different arities, all being fed one argument). I found Scott Turner's pure Haskell 98 solution very illuminating: http://www.haskell.org/pipermail/haskell-cafe/2000-November/001332.html Regards, Tom

Thanks for the link. So many variations on a theme:
n-vars to a list : Oleg's solution for polyvariadic functions
list + n-adic function -> value : This thread
list of (n_i)-adic functions + argument -> list of (n_i-1)-adic
functions : The link you gave.
The first two had very similar answers, and I have a feeling the third
could be answered with yet another application of the same idea.
As I see it, the answer given in that link amounts to wrapping the
function so that it will fit in a homogeneous list. The user still has
to wrap their functions with multiple 'cook's.
Joel
On 10/5/06, tpledger@ihug.co.nz
This came up a while ago (but with a list of functions of different arities, all being fed one argument). I found Scott Turner's pure Haskell 98 solution very illuminating:
http://www.haskell.org/pipermail/haskell-cafe/2000-November/001332.html
Regards, Tom
participants (2)
-
Joel Koerwer
-
tpledger@ihug.co.nz