박신환
2018-05-03 09:22:16 UTC
As instance Alternative ZipList is defined since 4.11.0.0:
instanceAlternativeZipListwhereempty=ZipList[]ZipList<|>ZipList=ZipList(xs++drop(lengthxs)ys)
It seems perfectly fine to make Monoid for ZipList as followings:
instance Semigroup a => Semigroup (ZipList a) where
ZipList [] <> ZipList ys = ZipList ys
ZipList xs <> ZipList [] = ZipList xs
ZipList (x:xs) <> ZipList (y:ys) = ZipList (x <> y : ZipList xs <> ZipList ys)
instance Semigroup a => Monoid (ZipList a) where
mempty = ZipList []
Note that this semantic is similar to that of Maybeâ.
instanceAlternativeZipListwhereempty=ZipList[]ZipList<|>ZipList=ZipList(xs++drop(lengthxs)ys)
It seems perfectly fine to make Monoid for ZipList as followings:
instance Semigroup a => Semigroup (ZipList a) where
ZipList [] <> ZipList ys = ZipList ys
ZipList xs <> ZipList [] = ZipList xs
ZipList (x:xs) <> ZipList (y:ys) = ZipList (x <> y : ZipList xs <> ZipList ys)
instance Semigroup a => Monoid (ZipList a) where
mempty = ZipList []
Note that this semantic is similar to that of Maybeâ.