[Haskell-beginners] Fwd: My first functioning haskell project - a steganography utility

Tim Cowlishaw tim at timcowlishaw.co.uk
Tue Jul 13 11:00:28 EDT 2010


On 13 Jul 2010, at 15:51, Brent Yorgey wrote:

> If it really is an instance of the Monoid type class then you could
> just write:
> 
>  maybeMonoid :: (Monoid a) => Maybe a -> Maybe a -> a
>  maybeMonoid x y = fromMaybe mempty $ liftM2 mappend x y


Aha, yes! that's exactly what I was getting at. Presumably I would also then define

Instance Monoid Int where
	mempty = 0
	mappend = (+)

(of course, Z also forms a monoid under multiplication, but we're not interested in that in this instance)

Cheers,

Tim


More information about the Beginners mailing list