<div dir="ltr"><div>I'm do not believe that that the FlexibleContexts-based instance is the best available option. The available options are:</div><div><br></div><div>    instance Semigroup (f (g a)) => Semigroup (Compose f g a) -- FlexibleContexts</div><div>    OR</div><div>    instance (forall x. Semigroup x => Semigroup (f x), forall x. Semigroup x => Semigroup (g x), Semigroup a) => Semigroup (Compose f g a) -- QuantifiedConstraints</div><div><br></div><div>There is a third option available which is to add Semigroup1 and Monoid1 typeclasses, but since the QuantifiedConstraints extension obsoletes such boilerplate, this option is not be considered here. David Feuer has pointed out in another thread that this context is satisfied by strictly more types than the context on the QuantifiedContstraints-based instance. However, I argue that the cost of this flexibility is composition. That is, the context does not break down into smaller contexts that can be satisfied individually. By constrast, the QuantifiedConstraints-based instance offers a context comprised of three distinct constraints. This is the same strategy employed by the Eq, Ord, Show, and Read instances. That is to say that the QuantifiedConstraints-based instances is consistent in spirit with the existing instances. And as the the Eq1/Ord1/...-based instances for Compose enable reasoning compositionally about constraints, so does QuantifiedConstraints-based Semigroup instance. Consider this contrived example that illustrates the principle:</div><div><br></div><div>foo :: ??? => Compose IO Maybe a -> Compose IO Maybe a -> Compose IO Maybe a<br></div><div>foo = (<>)<br></div><div><br></div><div>What context should fill in the question marks? With the QuantifiedConstraints-based instance, we would write `Semigroup a` (since the other two constraints are satisfied), but with the FlexibleContexts-based instance, we would write `Semigroup (IO (Maybe a))`. Bummer. I've encountered real scenarios where this is actually a problem although it would be tedious to explain them here. I'm happy to hear differing opinions or agreement. One way or another, we really ought to add something.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 26, 2019 at 9:17 AM Ryan Scott <<a href="mailto:ryan.gl.scott@gmail.com">ryan.gl.scott@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
You may find the discussion at<br>
<a href="https://mail.haskell.org/pipermail/libraries/2018-February/028571.html" rel="noreferrer" target="_blank">https://mail.haskell.org/pipermail/libraries/2018-February/028571.html</a><br>
interesting. The summarized version of that post is that<br>
Data.Functor.Compose was originally brought over from the transformers<br>
library, which adheres to a very Haskell98 mindset in its design. In<br>
particular, the maintainer of transformers would likely not have added<br>
the Semigroup or Monoid instances you propose, since they require the<br>
FlexibleContexts language extension. This explains why there exists an<br>
`instance (Eq1 f, Eq1 g, Eq a) => Eq (Compose f g a)` and not an<br>
`instance Eq (f (g a)) => Eq (Compose f g a)`, among other things.<br>
<br>
Of course, Data.Functor.Compose now lives in the base library, not<br>
transformers, so we need not prescribe to the same design philosophy.<br>
I don't feel too strongly about the issue, so if other people feel<br>
like adding Semigroup/Monoid instances that require FlexibleContexts<br>
is a good idea, I could get on board with that. What do others think?<br>
<br>
Ryan S.<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">-Andrew Thaddeus Martin</div>