2

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I absolutely thought it was a structure error, thank you. I'm attempting to map a function that compares two elements in a list, across an entire list of objects. So for each object I have to compare it to each other object in the list to calculate a motion for it.
With a bit of buggerising around I actually got map working properly, and the function that I've tested it on works appropriately as well: accelerate f (x:xs) = map (accelerateList f xs) xs Works wonderfully. Thanks for the help guys!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.