Applying a function to an arbitrarily long list of arguments
Posted
by alphomega
on Stack Overflow
See other posts from Stack Overflow
or by alphomega
Published on 2010-05-10T03:50:38Z
Indexed on
2010/05/10
3:58 UTC
Read the original article
Hit count: 291
haskell
I want to create a function apply that takes a function with an arbitrary amount of arguments as well as a list of integers, and returns the result of the function (Where each integer in the list is an argument in order.
I was thinking something like:
apply :: ([Int] -> Int) -> [Int] -> Int
apply f x:xs = apply (f x) xs
apply f [] = f
But I know this won't work because the type signature is wrong - the function doesn't take a list of ints, it just takes some amount of int arguments.
Additionally, when I get to the base case the f argument to apply should actually be an integer, violating the type signature anyway.
Does anyone know how to deal with this sort of problem?
© Stack Overflow or respective owner