Proposal: Add missing Monoid for ZipList

Edward Kmett ekmett at gmail.com
Sun Jul 26 15:42:41 UTC 2015


Fumiaka Kinoshita's instance actually seems both sound and "slightly more
defined".

It even relates more obviously to the proposed Alternative, which can be
seen as exploiting the fact that the First semigroup can be applied on any
data type and then using this instance.

m <|> n = fmap getFirst (fmap First m <> fmap First n)

-Edward


On Sat, Jul 25, 2015 at 11:43 PM, M Farkas-Dyck <strake888 at gmail.com> wrote:

> On 26/07/2015 at 12:23:13 +0900, Fumiaki Kinoshita wrote:
> > There is another possible instance:
> >
> > instance Semigroup a => Monoid (ZipList a) where
> >   mempty = ZipList []
> >   mappend (ZipList xs0) (ZipList ys0) = ZipList (mappend xs0 ys0) where
> >     go (x:xs) (y:ys) = x <> y : go xs ys
> >     go xs [] = xs
> >     go [] ys = ys
>
> This breaks the identity law.
> _______________________________________________
> 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/20150726/26dbdd6c/attachment.html>


More information about the Libraries mailing list