
aditya siram wrote:
You will have to write orMaybe as
orMaybe Nothing y = y orMaybe x _ = x
though. (By the way, your original code for orMaybe doesn't seem to do what you want.) This function has already been implemented for you, it's called
mplus
My function 'orMaybe' takes two arguments m1 m2, if one of them is Nothing, it returns Nothing, if m1 is Just , it returns m1, if m2 is Just, it returns m2. This seems to be what I want. Why is this incorrect?
Ah, you're right, my bad. I was confused by the fact that you were using it from right to left, i.e. findMaybe f = foldr (\a sofar -> sofar `orMaybe` a) Nothing . map f = foldr (flip orMaybe) Nothing . map f instead of findMaybe f = foldr orMaybe Nothing . map f Regards, apfelmus -- http://apfelmus.nfshost.com