Proposal: Add missing Monoid for ZipList

Fumiaki Kinoshita fumiexcel at gmail.com
Sun Jul 26 03:24:27 UTC 2015


Sorry, it should be `mappend (ZipList xs0) (ZipList ys0) = ZipList (go xs0
ys0) where`

2015-07-26 12:23 GMT+09:00 Fumiaki Kinoshita <fumiexcel at gmail.com>:

> 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
>
> But +1 to the original one.
>
> 2015-07-26 5:50 GMT+09:00 Christopher Allen <cma at bitemyapp.com>:
>
>>
>> http://hackage.haskell.org/package/base-4.8.1.0/docs/Control-Applicative.html#t:ZipList
>>
>> There's a Monoid that matches what the Applicative for ZipList does that
>> seems to be missing.
>>
>> instance Monoid a => Monoid (ZipList a) where
>>   mempty  = pure mempty
>>   mappend = liftA2 mappend
>>
>> It's been brought up before:
>>
>> https://mail.haskell.org/pipermail/haskell-cafe/2009-October/067861.html
>>
>> Not only is it useful when it's the Monoid you want, but it serves an
>> educational purpose for highlighting the relationship between Monoid and
>> Applicative as well.
>>
>> Are there any good reasons not to have it?
>>
>> I'd like to limit discussion to two weeks.
>>
>>
>> _______________________________________________
>> 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/21e7575a/attachment-0001.html>


More information about the Libraries mailing list