[Haskell-beginners] a simple little problem

Ertugrul Soeylemez es at ertes.de
Sat Aug 13 20:23:16 CEST 2011


Mihai Maruseac <mihai.maruseac at gmail.com> wrote:

> I'd go by:
>
> fn l = let l' = filter (/= Nothing) l in if l' == [] then Nothing else head l'

If you want to disregard the useful Monoid instance of Maybe, then here
is a nicer way to express this:

    fn :: [Maybe a] -> Maybe a
    fn = listToMaybe . catMaybes


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/





More information about the Beginners mailing list