Talk:Yet Another Haskell Tutorial/Type basics/Solutions

I don't think the solution to the first CPS exercise given here is correct.

The  function behaves just like. More interestingly, in the case of  the central difference between   and , the position of the recursive call (which is now contained inside the continuation), is left up to the function provided to.

And I also don't think the two solutions to the second CPS exercise are correct. I think they are both not in CPS.

I'm not sure if this is what was intended, but my solutions to this exercise do use CPS by calling :

cmap f = cfold' (\x t g -> (f x) : g t) []

cfilter f = cfold' (\x t g -> if f x then x : g t else g t) []

I agree

Don't you have to pass a function that acts as a continuation that will be called by the mapping function? Here are my solutions:

mlst2 f []      = [] mlst2 f (x:xs)  = f x (\x -> x : mlst2 f xs) cmap g xs       = mlst2 (\x f -> f (g x)) xs

cfilt' p []     = [] cfilt' p (x:xs) = p x (\x -> x : cfilt' p xs) (\x -> cfilt' p xs) cfilt p xs      = cfilt' (\x f g -> if p x then f x else g x) xs

-- Cool, I'm not the only one ... solutions from the book for these exercises aren't correct at all. These two last solutions are quite correct :-)