[Haskell-beginners] a simple little problem
Mihai Maruseac
mihai.maruseac at gmail.com
Sat Aug 13 20:41:39 CEST 2011
On Sat, Aug 13, 2011 at 9:23 PM, Ertugrul Soeylemez <es at ertes.de> wrote:
> 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
>
I stand corrected. I only wanted a simple solution but the Monoid
instance is more expressive :)
More information about the Beginners
mailing list