Proposal: Functor and friends for the wrappers in Data.Monoid

Edward Kmett ekmett at gmail.com
Sun Feb 22 07:56:37 UTC 2015


Many instances for data types in Data.Monoid have already been added in
7.10.

Are these still missing?

-Edward

On Sat, Feb 21, 2015 at 10:34 AM, Oleg Grenrus <oleg.grenrus at iki.fi> wrote:

> I propose to add Functor, Applicative, Monad, Foldable, and Traversable
> and maybe even MonadFix instances to wrapper newtypes in the Data.Monoid
> module.
> The same way as in the semigroups package, e.g.
> https://hackage.haskell.org/package/semigroups-0.16.1/docs/Data-Semigroup.html#t:Min
> <
> https://hackage.haskell.org/package/semigroups-0.16.1/docs/Data-Semigroup.html#t:Min
> >
>
> Basically:
>
> instance Functor Sum where
>   fmap f (Sum x) = Sum (f x)
>
> instance Foldable Sum where
>   foldMap f (Sum a) = f a
>
> instance Traversable Sum where
>   traverse f (Sum a) = Sum <$> f a
>
> instance Applicative Sum where
>   pure = Sum
>   a <* _ = a
>   _ *> a = a
>   Sum f <*> Sum x = Sum (f x)
>
> instance Monad Sum where
>   return = Sum
>   _ >> a = a
>   Sum a >>= f = f a
>
> instance MonadFix Sum where
>   mfix f = fix (f . getSum)
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150222/79de55cd/attachment-0001.html>


More information about the Libraries mailing list