[Haskell-beginners] Re: Searching Maybe lists

Heinrich Apfelmus apfelmus at quantentunnel.de
Tue May 19 12:45:25 EDT 2009


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



More information about the Beginners mailing list