HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulemonoid-extras-0.6.2Haskell2010

Data.Monoid.Split

Sometimes we want to accumulate values from some monoid, but have the ability to introduce a "split" which separates values on either side. Only the rightmost split is kept. For example,

a b c | d e | f g h == a b c d e | f g h

In the diagrams graphics framework this is used when accumulating transformations to be applied to primitive diagrams: the freeze operation introduces a split, since only transformations occurring outside the freeze should be applied to attributes.

  • 1 type
  • 2 values
datadata Split m
#

A value of type Split m is either a single m, or a pair of m's separated by a divider. Single m's combine as usual; single m's combine with split values by combining with the value on the appropriate side; when two split values meet only the rightmost split is kept, with both the values from the left split combining with the left-hand value of the right split.

Data.Monoid.Cut is similar, but uses a different scheme for composition. Split uses the asymmetric constructor :|, and Cut the symmetric constructor :||:, to emphasize the inherent asymmetry of Split and symmetry of Cut. Split keeps only the rightmost split and combines everything on the left; Cut keeps the outermost splits and throws away everything in between.

Constructors

  • M m
  • m :| minfix 5
Instances10Functor, Foldable, Traversable, Eq, Data, Read, …
  • Functor SplitDefined in monoid-extras-0.6.2 · Data.Monoid.Split
  • Foldable SplitDefined in monoid-extras-0.6.2 · Data.Monoid.Split
  • Traversable SplitDefined in monoid-extras-0.6.2 · Data.Monoid.Split
  • Eq m => Eq (Split m)Defined in monoid-extras-0.6.2 · Data.Monoid.Split
  • Data m => Data (Split m)Defined in monoid-extras-0.6.2 · Data.Monoid.Split
  • Read m => Read (Split m)Defined in monoid-extras-0.6.2 · Data.Monoid.Split
  • Show m => Show (Split m)Defined in monoid-extras-0.6.2 · Data.Monoid.Split
  • Semigroup m => Semigroup (Split m)Defined in monoid-extras-0.6.2 · Data.Monoid.Split

    If m is a Semigroup, then Split m is a semigroup which combines values on either side of a split, keeping only the rightmost split.

  • (Semigroup m, Monoid m) => Monoid (Split m)Defined in monoid-extras-0.6.2 · Data.Monoid.Split
  • Action m n => Action (Split m) nDefined in monoid-extras-0.6.2 · Data.Monoid.Split

    By default, the action of a split monoid is the same as for the underlying monoid, as if the split were removed.

valuesplit :: Monoid m => Split m
#

A convenient name for mempty :| mempty, so M a <> split <> M b == a :| b.

valueunsplit :: Semigroup m => Split m -> m
#

"Unsplit" a split monoid value, combining the two values into one (or returning the single value if there is no split).