HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulemonoid-extras-0.6.2Haskell2010

Data.Monoid.Coproduct

The coproduct of two monoids.

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

m :+: n is the coproduct of monoids m and n. Values of type m :+: n consist of alternating lists of m and n values. The empty list is the identity, and composition is list concatenation, with appropriate combining of adjacent elements when possible.

Instances4Show, Semigroup, Monoid, Action
  • (Show m, Show n) => Show (m :+: n)Defined in monoid-extras-0.6.2 · Data.Monoid.Coproduct
  • Semigroup (m :+: n)Defined in monoid-extras-0.6.2 · Data.Monoid.Coproduct
  • Monoid (m :+: n)Defined in monoid-extras-0.6.2 · Data.Monoid.Coproduct

    The coproduct of two monoids is itself a monoid.

  • (Action m r, Action n r) => Action (m :+: n) rDefined in monoid-extras-0.6.2 · Data.Monoid.Coproduct

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

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

Injection from the left monoid into a coproduct.

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

Injection from the right monoid into a coproduct.

valuemappendL :: m -> m :+: n -> m :+: n
#

Prepend a value from the left monoid.

valuemappendR :: n -> m :+: n -> m :+: n
#

Prepend a value from the right monoid.

valuekillL :: Monoid n => m :+: n -> n
#

killL takes a value in a coproduct monoid and sends all the values from the left monoid to the identity.

valuekillR :: Monoid m => m :+: n -> m
#

killR takes a value in a coproduct monoid and sends all the values from the right monoid to the identity.

valueuntangle :: (Action m n, Monoid m, Monoid n) => m :+: n -> (m, n)
#

Take a value from a coproduct monoid where the left monoid has an action on the right, and "untangle" it into a pair of values. In particular,

m1 <> n1 <> m2 <> n2 <> m3 <> n3 <> ...

is sent to

(m1 <> m2 <> m3 <> ..., (act m1 n1) <> (act (m1 <> m2) n2) <> (act (m1 <> m2 <> m3) n3) <> ...)

That is, before combining n values, every n value is acted on by all the m values to its left.