Functors supporting a
zip operation that takes the intersection
of non-uniform shapes.
Minimal definition: either
zip or
zipWith.
Idempotency
join zip ≡ fmap (join (,))
Commutativity
zip x y ≡ swap <$> zip y x
Associativity
zip x (zip y z) ≡ assoc <$> zip (zip x y) z
Absorption
fst <$> zip xs (align xs ys) ≡ xs
toThis <$> align xs (zip xs ys) ≡ This <$> xs
where
toThis (This a) = This a
toThis (These a _) = This a
toThis (That b) = That b
With
zipWith f a b ≡ f <$> zip a b
Functoriality
zip (f <$> x) (g <$> y) ≡ bimap f g <$> zip x y
Zippyness
fmap fst (zip x x) ≡ x
fmap snd (zip x x) ≡ x
zip (fmap fst x) (fmap snd x) ≡ x
Distributivity
align (zip xs ys) zs ≡ undistrThesePair <$> zip (align xs zs) (align ys zs)
distrPairThese <$> zip (align xs ys) zs ≡ align (zip xs zs) (zip ys zs)
zip (align xs ys) zs ≡ undistrPairThese <$> align (zip xs zs) (zip ys zs)
Note, the following doesn't hold:
distrThesePair <$> align (zip xs ys) zs ≢ zip (align xs zs) (align ys zs)
when
xs = [] and
ys = zs = [0], then the left hand
side is "only"
[(That 0, That 0)], but the
right hand side is
[(That 0, These 0 0)].