[Haskell-cafe] Re: The danger of Monad ((->) r)
Jules Bean
jules at jellybean.co.uk
Wed May 16 04:28:31 EDT 2007
Tomasz Zielonka wrote:
> On Tue, May 15, 2007 at 06:55:11AM -0700, Conal Elliott wrote:
>
>> You could also use mappend instead of concatStmts and keep the Database ->
>> IO () representation. - Conal
>>
>
> 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 >>.
MonadPlusses have a Monoid structure at each particular fixed type,
using mplus, but it's not the same one in all but the most trivial case.
E.g:
Prelude System.IO Control.Monad> Just 3 >> Nothing
Nothing
Prelude System.IO Control.Monad> Just 3 `mplus` Nothing
Just 3
The general point here is that an awful lot of things are Monoids, often
in more than one way. There isn't a really elegant way to choose which
instance you want, though. newtype hackery is one way to partition them,
although it might be nicer (?) to have a more general notion of 'naming
instances'.
Jules
More information about the Haskell-Cafe
mailing list