monoid-extras-0.7: Various extra monoid-related definitions and utilities

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Semigroup.Coproduct

Synopsis

- data m :+. n
- inL :: m -> m :+. n
- inR :: n -> m :+. n
- cop :: Semigroup k => (m -> k) -> (n -> k) -> (m :+. n) -> k
- toAltList :: (Semigroup m, Semigroup n) => (m :+. n) -> NonEmpty (Either m n)
- toMonoid :: (Monoid m, Monoid n) => (m :+. n) -> m :+: n

# Documentation

data m :+. n Source #

`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

Instances details

Semigroup (m :+. n) Source # |
Instance details Defined in Data.Semigroup.Coproduct Methods (<>) :: (m :+. n) -> (m :+. n) -> m :+. n Source # sconcat :: NonEmpty (m :+. n) -> m :+. n Source # stimes :: Integral b => b -> (m :+. n) -> m :+. n Source #
(Show m, Show n) => Show (m :+. n) Source # |
Instance details Defined in Data.Semigroup.Coproduct Methods showsPrec :: Int -> (m :+. n) -> ShowS Source # show :: (m :+. n) -> String Source # showList :: [m :+. n] -> ShowS Source #
(Eq m, Eq n, Semigroup m, Semigroup n) => Eq (m :+. n) Source # |
Instance details Defined in Data.Semigroup.Coproduct Methods (==) :: (m :+. n) -> (m :+. n) -> Bool Source # (/=) :: (m :+. n) -> (m :+. n) -> Bool 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.
Instance details Defined in Data.Semigroup.Coproduct Methods act :: (m :+. n) -> r -> r Source #

inL :: m -> m :+. n Source #

Injection from the left semigroup into a coproduct.

inR :: n -> m :+. n Source #

Injection from the right semigroup into a 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`.