
6 Mar
2007
6 Mar
'07
2:09 p.m.
On 06/03/07, Ross Paterson
There is another, combining two Justs using a Monoid instance on the argument. It could be argued that this is an even better candidate for the "obvious" instance on Maybe.
Like this? instance Monoid a => Monoid (Maybe a) where mempty = Nothing Just xs `mappend` Just ys = Just (xs `mappend` ys) _ `mappend` _ = Nothing I was under the impression that such an instance was already in the libraries, but looking at the Haddocks it appears I'm wrong. Indeed, one could write a generic instance: instance (Functor f, FunctorZero f, Monoid a) => Monoid (f a) where mempty = fzero mappend = fmap mappend Assuming a: class FunctorZero f where fzero :: f a -- -David House, dmhouse@gmail.com