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

apfelmus apfelmus at quantentunnel.de
Wed May 28 05:21:01 EDT 2008


Ross Paterson wrote:
> Several functions on containers used to have types like
> 
> 	lookup :: (Ord k) => k -> Map k a -> Maybe a
> 
> but these were generalized to
> 
> 	lookup :: (Monad m, Ord k) => k -> Map k a -> m a
> 
> The proposal is to change these signatures back, specializing them
> to Maybe.

I'm all for Maybe in the question Monad VS Maybe.


Concerning MonadZero VS Maybe, the first observation is of course that 
both approaches have the same expressiveness,

   lift   :: MonadZero m => Maybe a -> m a
   lift = maybe mzero return

   unlift :: (forall m . MonadZero m => m a) -> Maybe a
   unlift = id

are inverse to each other. In other words,  Maybe  has a universal 
property (this sounds much fancier than it really is).

So, the only decision here is whether the library should factor things 
via Maybe or include an automatic  lift  for extra convenience. I'm not 
sure whether this convenience is actually used, can someone dig up 
statistics from hackage?

Also, it's not entirely clear whether MonadZero is the most general 
abstraction. Is ApplicativeZero better? Or something else?

In any case, I prefer Maybe here as well because it's straightforward 
and simple. Every other abstraction is just a  lift  away.


Regards,
apfelmus



More information about the Libraries mailing list