Proposal: Functor and friends for the wrappers in Data.Monoid
Oleg Grenrus
oleg.grenrus at iki.fi
Tue Feb 24 17:21:44 UTC 2015
D is already implemented:
https://phabricator.haskell.org/rGHC1f60d635cee1ff3db72e0129f9035b147f52c9c4 <https://phabricator.haskell.org/rGHC1f60d635cee1ff3db72e0129f9035b147f52c9c4>
https://ghc.haskell.org/trac/ghc/ticket/9664 <https://ghc.haskell.org/trac/ghc/ticket/9664>
Seems it just (~30 hours ago) landed the 7.10 branch https://git.haskell.org/ghc.git/blob/refs/heads/ghc-7.10:/libraries/base/Data/Functor/Identity.hs <https://git.haskell.org/ghc.git/blob/refs/heads/ghc-7.10:/libraries/base/Data/Functor/Identity.hs>
So, it’s only A, B, C options in discussion anymore.
- Oleg
> On 22 Feb 2015, at 12:07, Oleg Grenrus <oleg.grenrus at iki.fi> wrote:
>
> To clarify the discussion:
>
> Let's add the following instances:
>
> A: Functor, Foldable, Traversable to Sum, Product, Dual, First, and Last
> B: Data to everything in Data.Monoid (except Endo): Sum, Product, Dual, First and Last, All, Any, Alt
> C: Applicative, Monad, MonadFix to Sum, Product, Dual, First and Last
> D: Data to Identity
>
> All seem to agree on A and B, C is "not sure", and D is new item.
>
> - Oleg
>
>> On 21 Feb 2015, at 17:34, 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
>
> _______________________________________________
> 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/20150224/47f1c34d/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150224/47f1c34d/attachment-0001.sig>
More information about the Libraries
mailing list