Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Data.Semigroup.Coproduct
Documentation
m :+. n
is the coproduct of semigroups m
and n
. Values of
type m :+. n
consist of alternating non-empty lists of m
and n
values. Composition is list concatenation, with appropriate
combining of adjacent elements
Instances
Semigroup (m :+. n) Source # | |
(Show m, Show n) => Show (m :+. n) Source # | |
(Eq m, Eq n, Semigroup m, Semigroup n) => Eq (m :+. n) Source # | |
(Action m r, Action n r) => Action (m :+. n) r Source # | Coproducts act on other things by having each of the components act individually. |
Defined in Data.Semigroup.Coproduct |
cop :: Semigroup k => (m -> k) -> (n -> k) -> (m :+. n) -> k Source #
Universal map of the coproduct. The name cop
is an abbreviation
for copairing. Both functions in the signature should be semigroup
homomorphisms. If they are general functions then the copairing may
not be well defined in the sense that it may send equal elements to
unequal elements. This is also the reason why cop
is not the
Data.Bifoldable1.bifoldMap1
function even though they have the same
signature.
toAltList :: (Semigroup m, Semigroup n) => (m :+. n) -> NonEmpty (Either m n) Source #
Extract a semigroup coproduct to a non-empty list of Either
values.
The resulting list is guaranteed to be normalized, in the sense that
it will strictly alternate between Left
and Right
.
toMonoid :: (Monoid m, Monoid n) => (m :+. n) -> m :+: n Source #
Given monoids m
and n
, we can form their semigroup coproduct
m :+. n
. Every monoid homomorphism is a semigroup homomorphism.
In particular the canonical inections of the monoid coproduct from
m
and n
into m :+: n
are semigroup homomorphisms. By pairing
them using the universal property of the semigroup coproduct we
obtain a canonical semigroup homomorphism toMonoid
from m :+. n
to m :+: n
.