Applying a function with multiple inputs using Map? (Haskell)
문제
G'day guys,
Trying currently to finish up a bit of homework I'm working on, and having an issue where I'm trying to apply map across a function that accepts multiple inputs.
so in the case I'm using processList f (x:xs) = map accelerateList f xs x xs
processList is given a floating value (f) and a List that it sorts into another List
Accelerate List takes a floating value (f) a List and a List Object through which it returns another List Object
I know my Accelerate List code is correct, but I cannot for the life of me get the syntax for this code working:
processList :: Float -> [Object] -> [Object]
accelerate f [] = []
accelerate f [x] = [(accelerateForce f x x)]
accelerate f (x:xs) = map accelerateList f xs x xs
Any ideas? I've been scratching my head for about 3 hours now. I know it's something really simple.
해결책
First of you will probably want to use some parenthesis here:
map accelerateList f xs x xs
The function map
takes exactly two arguments (not five), so you should do something like this for example:
map (accelerateList f xs x) xs
But on the other hand, that doesn't fit with your function signatures. The problem is probably that you haven't structured your solution in a good enough way. Might be a separate question, but explaining what you're trying to accomplish with the accelerate-function (or which ever one is the "top" one) would certainly help.