[Haskell-cafe] Error Monad and strings

Evan Laforge qdunkan at gmail.com
Wed Jul 28 03:50:51 EDT 2010


> 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'.


More information about the Haskell-Cafe mailing list