simple task: all I want is a function to apply a list of parameters to a curried function.
Let's say our function is the famous
fun add a b = a + b;
Now all I want is a function to apply a list (say
[1, 5]) to
add. This would then look like:
apply add [1, 5];
This seems to be harder than I thought. My try:
fun apply f ps = foldl (fn (p, f') => f' p) f ps;
But this gets this hilarious readable error message:
Error: operator and operand don't agree [circularity] operator domain: 'Z * ('Z -> 'Y) -> 'Z -> 'Y operand: 'Z * ('Z -> 'Y) -> 'Y in expression: foldl (fn (p,f') => f' p)
Now, what is wrong about my implementation? Is it even possible in SML/NJ?
Cheers and thanks for hints and answers.