reset password
Author Message
lren2
Posts: 5
Posted 21:24 Feb 10, 2019 |

Hello, I'm responsible for number 6 and it's been driving me up the walls. So creating a functionPair with foldr seems impossible as foldr takes an argument like this:

foldr (some operation, so like a function) (list or number that this operation is gonna do) (other list that its gonna be applied to)

In my Haskell code, I'm having trouble implementing foldr because what it does is ACCUMULATES the numbers instead of applying the function to each one. I'm not sure how to split it or is the only way to do this some kind of loop in Haskell? I know it's last moment but any help would be greatly appreciated.

rabbott
Posts: 1649
Posted 21:35 Feb 10, 2019 |

Can you do it with map?

The way to turn a map solution into a fold solution is to build the list of results in the accumulator. That is, for each new input, apply the function, create the tuple, and then add that tuple to the list in the accumulator. The accumulator should start with an empty list. For each new input element, it gets one element longer.