
This may be a stupid question, but I'm wondering why the following instance isn't in prelude: instance (Applicative m, Monoid a) => Monoid (m a) where mempty = pure mempty mappend a b = mappend <$> a <*> b ? I ask, because being able to use a WriterT (IO ()) STM a to debug complex STM expressions would be really nice. But it depends upon IO () being a monoid. Brian

Probably something to do with not making overlapping instances. Not sure. Easiest/best approach is probably to make a newtype wrapper around IO or IO (). Then you can define the monoid instance you want. Will
On Sep 5, 2016, at 13:54, Brian Hurt
wrote: This may be a stupid question, but I'm wondering why the following instance isn't in prelude:
instance (Applicative m, Monoid a) => Monoid (m a) where mempty = pure mempty mappend a b = mappend <$> a <*> b
?
I ask, because being able to use a WriterT (IO ()) STM a to debug complex STM expressions would be really nice. But it depends upon IO () being a monoid.
Brian
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Instance overlap would break a lot of Monad instances (notably [a]),
IIRC. This instance comes up on the mailing list every two or three
years, it looks like.
2007: https://mail.haskell.org/pipermail/libraries/2007-March/006997.html
2011: https://mail.haskell.org/pipermail/libraries/2011-December/017369.html
2013: http://haskell.1045720.n5.nabble.com/MonadPlus-instance-for-ContT-tp5732028p...
There's a newtype-wrapped version of this in Control.Compose [1]
[1]: https://hackage.haskell.org/package/TypeCompose-0.9.11/docs/Control-Compose....
Brian Hurt
This may be a stupid question, but I'm wondering why the following instance isn't in prelude:
instance (Applicative m, Monoid a) => Monoid (m a) where mempty = pure mempty mappend a b = mappend <$> a <*> b
?
I ask, because being able to use a WriterT (IO ()) STM a to debug complex STM expressions would be really nice. But it depends upon IO () being a monoid.
Brian _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- Jack

On Mon, Sep 05, 2016 at 02:54:20PM -0400, Brian Hurt wrote:
This may be a stupid question, but I'm wondering why the following instance isn't in prelude:
instance (Applicative m, Monoid a) => Monoid (m a) where mempty = pure mempty mappend a b = mappend <$> a <*> b
?
Is 'liftA2 (<>)' not good enough?

I believe this is the App newtype in the monoids package [0].
Erik
[0] https://hackage.haskell.org/package/monoids-0.3.2/docs/
Data-Monoid-Applicative.html#t:App
On 5 September 2016 at 20:54, Brian Hurt
This may be a stupid question, but I'm wondering why the following instance isn't in prelude:
instance (Applicative m, Monoid a) => Monoid (m a) where mempty = pure mempty mappend a b = mappend <$> a <*> b
?
I ask, because being able to use a WriterT (IO ()) STM a to debug complex STM expressions would be really nice. But it depends upon IO () being a monoid.
Brian
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (5)
-
Brian Hurt
-
Erik Hesselink
-
Jack Henahan
-
Tom Ellis
-
Will Yager