<div dir="ltr">There are monads for which you want another Monoid, e.g. Maybe provides a different unit, because it pretends to lift a Semigroup into a Monoid.<div><br></div><div>There are also monoids that take a parameter of kind * that would overlap with this instance.</div>
<div><br></div><div>So we can't (and shouldn't) have the global Monoid instance like you give there first.</div><div><br></div><div>As for the particular case of IO a, lifting may be a reasonable option there. </div>
<div><br></div><div>A case could be made for adding an `instance Monoid a => Monoid (IO a)`, but for such a ubiquitously used type, expect that this wouldn't be an easy sell. </div><div><br></div><div>You'd possibly have to deal with everyone and their brother coming out of the woodwork offering up every other Monoid they happened to use on IO. </div>
<div><br></div><div>Why? </div><div><br></div><div>IO provides a notion of failing action you could use for zero and you can build an (<|>) like construction on it as well, so the 'multiplicative' structure isn't the _only_ option for your monoid. </div>
<div><br></div><div>Even within the multiplicative structure using the monoid isn't necessarily ideal as you might leak more memory with an IO a monoid that lifts () than you would with working specifically on IO ().</div>
<div><br></div><div>You can argue the case that the choice you made is a sensible default instance by instance, but when there isn't a real canonical choice we do tend to err on the side of leaving things open as orphans are at least possible, but once the choice is made it is very very hard to unmake.</div>
<div><br></div><div>I say this mostly so you know the kinds of objections proposals like this usually see, not to flat out reject the idea of the particular case of this instance for IO.</div><div><br></div><div>I will say the global 'instance (Applicative f, Monoid m) => Monoid (f m)' won't fly for overlap reasons though.</div>
<div><br></div><div>-Edward</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 14, 2014 at 6:55 PM, Brandon Simmons <span dir="ltr"><<a href="mailto:brandon.m.simmons@gmail.com" target="_blank">brandon.m.simmons@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It seems to me that this should be true for all `f a` like:<br>
<br>
  instance (Monoid a, Applicative f)=> Monoid (f a) where<br>
      mappend = liftA2 mappend<br>
      mempty = pure mempty<br>
<br>
But I can't seem to find the particular `instance (Monoid a)=> Monoid<br>
(IO a)` anywhere. Would that instance be incorrect, or does it live<br>
somewhere else?<br>
<br>
FWIW I noticed this when I started thinking about an instance I wanted<br>
for 'contravariant':<br>
<br>
  instance (Monoid a, Applicative f)=> Monoid (Op (f a) b) where<br>
      mempty = Op $ const $ pure mempty<br>
      mappend (Op f) (Op g) = Op (\b-> liftA2 mappend (f b) (g b))<br>
<br>
at which point I realized (I think) all `f a` are monoidal, and so we<br>
ought to be able to get the instance above with just a deriving<br>
Monoid.<br>
<br>
Brandon<br>
_______________________________________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users" target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
</blockquote></div><br></div>