Skip to content

instance Alternative ZipList

The paper "From monoids to near-semirings: the essence of MonadPlus and Alternative" mentions

Perhaps surprisingly, ZipLists have an Alternative instance. Like the Alternative instance for Maybe, the one for ZipList has a left bias.

instance Alternative ZipList where
empty :: ZipList a
empty           = ZL []

(<|>) :: ZipList a -> ZipList a -> ZipList a
ZL xs <|> ZL ys = ZL (xs ++ drop (length xs) ys)

Has this been considered for base?

Edited by Icelandjack
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information