Proposal: Add missing Monoid for ZipList

Henning Thielemann lemming at henning-thielemann.de
Sun Jul 26 06:30:33 UTC 2015


On Sun, 26 Jul 2015, Oleg Grenrus wrote:

>> On 26 Jul 2015, at 06:43, 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.

I don't see, how it breaks the identity law. :-(


>    instance Monoid a a => Monoid (ZipList a) where
>      mempty = ZipList (repeat mempty)
>      mappend (ZipList xs) (ZipList ys) = ZipList (zipWith (<>) xs ys)

This was the original proposal, isn't it?


Since there does not seem to be a real application for the instance there 
is no way to choose a particular one. But then it is better to omit the 
instance, at all. Not having an instance can be a good thing in terms of 
(type) safety.


More information about the Libraries mailing list