[Haskell-cafe] Re: The danger of Monad ((->) r)

Jules Bean jules at jellybean.co.uk
Wed May 16 04:42:59 EDT 2007


Tomasz Zielonka wrote:
> On Wed, May 16, 2007 at 09:28:31AM +0100, Jules Bean wrote:
>   
>> Tomasz Zielonka wrote:
>>     
>>> You mean using the (Monoid b) => Monoid (a -> b) instance ?
>>> I can see that IO () makes a perfect Monoid, but there doesn't seem to
>>> be a standard instance for that.
>>>       
>> Indeed, all Monads are Monoids (that is, if m :: * -> * is a Monad, then 
>> m a :: * is a Monoid, for any fixed type a) by using >>.
>>     
>
> Are you sure that (IO Int) is a monoid with mappend = (>>)? How do you
> define mempty, so it is an identity for mappend?
>
> It would help if type a was a Monoid, then:
>
>     mempty = return mempty
>     mappend mx my = do
>         x <- mx
>         y <- my
>         return (x `mappend` y)
>
> It's easier if a = ().
>   

Oops, you're right. I spoke too fast.

It's only a monoid for (). Otherwise you can't hope to have a right 
identity.

Jules



More information about the Haskell-Cafe mailing list