
28 Jul
2010
28 Jul
'10
3:50 a.m.
I've always thought that being able to write:
catMaybes :: [Maybe a] -> [a] catMaybes xs = [ x | Just x <- xs ]
is really cool, which relies on:
fail _ = []
being in the Monad instance for List.
Really? I thought that's just a feature of list comprehensions. List comps are not monads, at least not any more. If you wrote it as: catMaybes xs = do Just x <- xs return x Then yes, I believe that uses 'fail'.