HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Modulemonoid-extras-0.7.0.2Haskell2010

Data.Semigroup.Coproduct

  • 1 type
  • 5 values
newtypenewtype (:+.) m n
#

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

Instances4Eq, Show, Semigroup, Action
  • (Eq m, Eq n, Semigroup m, Semigroup n) => Eq (m :+. n)Defined in monoid-extras-0.7.0.2 · Data.Semigroup.Coproduct
  • (Show m, Show n) => Show (m :+. n)Defined in monoid-extras-0.7.0.2 · Data.Semigroup.Coproduct
  • Semigroup (m :+. n)Defined in monoid-extras-0.7.0.2 · Data.Semigroup.Coproduct
  • (Action m r, Action n r) => Action (m :+. n) rDefined in monoid-extras-0.7.0.2 · Data.Semigroup.Coproduct

    Coproducts act on other things by having each of the components act individually.

valueinL :: m -> m :+. n
#

Injection from the left semigroup into a coproduct.

valueinR :: n -> m :+. n
#

Injection from the right semigroup into a coproduct.

valuecop :: Semigroup k => (m -> k) -> (n -> k) -> m :+. n -> k
#

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.

valuetoAltList :: (Semigroup m, Semigroup n) => m :+. n -> NonEmpty (Either m n)
#

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.

valuetoMonoid :: (Monoid m, Monoid n) => m :+. n -> m :+: n
#

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.