<p dir="ltr">+1 do all instances of the proposal. It is so common for me to want to use some polymorphic function but it not be available to me because it has a constraint not satisfied by a newtype wrapper around the type I want to use it with, so I have to write a bunch of boilerplate. I think we should eliminate such boilerplate aggressively. I even think Applicative and Monad would be useful. Just because a wrapper doesn't add behavior doesn't mean we should intentionally make it incompatible with so much code.<br>
</p>
<br><div class="gmail_quote">On 5:07AM, Sun, Feb 22, 2015 Oleg Grenrus <<a href="mailto:oleg.grenrus@iki.fi">oleg.grenrus@iki.fi</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">To clarify the discussion:<br>
<br>
Let's add the following instances:<br>
<br>
A: Functor, Foldable, Traversable to Sum, Product, Dual, First, and Last<br>
B: Data to everything in Data.Monoid (except Endo): Sum, Product, Dual, First and Last, All, Any, Alt<br>
C: Applicative, Monad, MonadFix to Sum, Product, Dual, First and Last<br>
D: Data to Identity<br>
<br>
All seem to agree on A and B, C is "not sure", and D is new item.<br>
<br>
- Oleg<br>
<br>
> On 21 Feb 2015, at 17:34, Oleg Grenrus <<a href="mailto:oleg.grenrus@iki.fi" target="_blank">oleg.grenrus@iki.fi</a>> wrote:<br>
><br>
> I propose to add Functor, Applicative, Monad, Foldable, and Traversable and maybe even MonadFix instances to wrapper newtypes in the Data.Monoid module.<br>
> The same way as in the semigroups package, e.g. <a href="https://hackage.haskell.org/package/semigroups-0.16.1/docs/Data-Semigroup.html#t:Min" target="_blank">https://hackage.haskell.org/<u></u>package/semigroups-0.16.1/<u></u>docs/Data-Semigroup.html#t:Min</a> <<a href="https://hackage.haskell.org/package/semigroups-0.16.1/docs/Data-Semigroup.html#t:Min" target="_blank">https://hackage.haskell.org/<u></u>package/semigroups-0.16.1/<u></u>docs/Data-Semigroup.html#t:Min</a><u></u>><br>
><br>
> Basically:<br>
><br>
> instance Functor Sum where<br>
>  fmap f (Sum x) = Sum (f x)<br>
><br>
> instance Foldable Sum where<br>
>  foldMap f (Sum a) = f a<br>
><br>
> instance Traversable Sum where<br>
>  traverse f (Sum a) = Sum <$> f a<br>
><br>
> instance Applicative Sum where<br>
>  pure = Sum<br>
>  a <* _ = a<br>
>  _ *> a = a<br>
>  Sum f <*> Sum x = Sum (f x)<br>
><br>
> instance Monad Sum where<br>
>  return = Sum<br>
>  _ >> a = a<br>
>  Sum a >>= f = f a<br>
><br>
> instance MonadFix Sum where<br>
>  mfix f = fix (f . getSum)<br>
> ______________________________<u></u>_________________<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" target="_blank">http://mail.haskell.org/cgi-<u></u>bin/mailman/listinfo/libraries</a><br>
<br>
______________________________<u></u>_________________<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" target="_blank">http://mail.haskell.org/cgi-<u></u>bin/mailman/listinfo/libraries</a><br>
</blockquote></div>