#2309: containers: specialize functions that fail in a Monad to Maybe

Isaac Dupree isaacdupree at charter.net
Sun May 25 11:36:14 EDT 2008

well, what we need is (unit :: a -> m a) and (zero :: m a).  Maybe gives 
us that nicely (Just,Nothing).  Monad is not nice, (return,fail "..."). 
  MonadPlus has (return,mzero) BUT is too specific, as some types with a 
(unit,zero) aren't even Monads, or don't have mplus.  Alternative (of 
Applicative fame) has (pure,empty) and no "fail" to be confused with... 
but it's less used yet, and it still requires fmap, ap and mplus (er, I 
mean, <*> and <|>).

Do we want every return type that's simple pattern-matchable data to be 
a type-class instead, so that we can have fewer explicit conversions 
applied to them? (I suppose this is considered explicit deforestation in 
the sense that ndm says GHC doesn't know how to do with returned "data")

I was assuming that we don't want that, and that therefore I prefer 
Maybe.  But I'm not sure anymore.  It seems that can give conciseness 
without harm... except for making it harder to tell what type everything 
is (when looking a text-editor that doesn't know Haskell type inference).


More information about the Libraries mailing list