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

Modulelinear-base-0.4.0Haskell2010

Data.Monoid.Linear.Internal.Semigroup

This module provides a linear version of Semigroup.

  • 9 types
  • 1 class
  • 1 value

Semigroup

1 declaration
classclass Semigroup a where
#

A linear semigroup a is a type with an associative binary operation <> that linearly consumes two as.

Laws (same as Semigroup): * ∀ x ∈ G, y ∈ G, z ∈ G, x <> (y <> z) = (x <> y) <> z

Methods

  • (<>) :: a %1 -> a %1 -> ainfixr 6
Instances41Semigroup, …
  • Semigroup VoidDefined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup AllDefined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup AnyDefined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup OrderingDefined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup ()Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup a => Semigroup (Ur a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup

    Useful to treat unrestricted semigroups as linear ones.

  • Semigroup (NonEmpty a)Defined in linear-base-0.4.0 · Data.List.Linear · orphan
  • Semigroup (Array a)Defined in linear-base-0.4.0 · Data.Array.Polarized.Pull.Internal
  • Semigroup (Array a)Defined in linear-base-0.4.0 · Data.Array.Polarized.Push
  • Semigroup (ArrayWriter a)Defined in linear-base-0.4.0 · Data.Array.Polarized.Push
  • Semigroup (Endo a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup (Vector a)Defined in linear-base-0.4.0 · Data.Vector.Mutable.Linear.Internal
  • Semigroup [a]Defined in linear-base-0.4.0 · Data.List.Linear · orphan
  • Semigroup a => Semigroup (Identity a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup a => Semigroup (Down a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup a => Semigroup (Dual a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup a => Semigroup (Maybe a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup a => Semigroup (IO a)Defined in linear-base-0.4.0 · System.IO.Linear
  • Semigroup a => Semigroup (RIO a)Defined in linear-base-0.4.0 · System.IO.Resource.Linear.Internal
  • Semigroup a => Semigroup (a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Additive a => Semigroup (Sum a)Defined in linear-base-0.4.0 · Data.Num.Linear · orphan
  • Additive a => Semigroup (Adding a)Defined in linear-base-0.4.0 · Data.Num.Linear
  • Multiplicative a => Semigroup (Product a)Defined in linear-base-0.4.0 · Data.Num.Linear · orphan
  • Multiplicative a => Semigroup (Multiplying a)Defined in linear-base-0.4.0 · Data.Num.Linear
  • Keyed a => Semigroup (Set a)Defined in linear-base-0.4.0 · Data.Set.Mutable.Linear.Internal
  • Consumable a => Semigroup (First a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Consumable a => Semigroup (Last a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Consumable a => Semigroup (First a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Consumable a => Semigroup (Last a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • (Movable a, Semigroup a) => Semigroup (MovableMonoid a)Defined in linear-base-0.4.0 · Data.Unrestricted.Linear.Internal.Instances
  • Keyed k => Semigroup (HashMap k v)Defined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
  • Semigroup (Proxy a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • (Semigroup a, Semigroup b) => Semigroup (a, b)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • (Consumable a, Consumable b) => Semigroup (Either a b)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup a => Semigroup (Const a b)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • (Applicative f, Semigroup a) => Semigroup (Ap f a)Defined in linear-base-0.4.0 · Data.Functor.Linear.Internal.Applicative · orphan
  • (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • (Semigroup (f a), Semigroup (g a)) => Semigroup (Product f g a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • (Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Semigroup (f (g a)) => Semigroup (Compose f g a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • (Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup

Endo

2 declarations
newtypenewtype Endo a
#

An Endo a is just a linear function of type a %1-> a. This has a classic monoid definition with id and (.).

Constructors

  • Endo (a %1 -> a)
Instances4Monoid, Semigroup
  • Semigroup (Endo a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Monoid (Endo a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Monoid · orphan
  • Monoid (Endo a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Monoid
  • Semigroup (Endo a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
valueappEndo :: Endo a %1 -> a %1 -> a
#

A linear application of an Endo.

NonLinear newtype

1 declaration
newtypenewtype NonLinear a
#

DerivingVia combinator for Semigroup (resp. Prelude.Monoid) given linear Semigroup (resp. Monoid).

newtype Endo a = Endo (a %1-> a)
  deriving (Prelude.Semigroup) via NonLinear (Endo a)

Constructors

  • NonLinear a
Instances2Semigroup, Monoid
  • Semigroup a => Semigroup (NonLinear a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • (Semigroup a, Monoid a) => Monoid (NonLinear a)Defined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Monoid · orphan

Data.Semigroup reexports

7 declarations
newtypenewtype All
#

Boolean monoid under conjunction (&&).

All x <> All y = All (x && y)
Examples
Example1 expression
All True <> mempty <> All False)All {getAll = False}
Example1 expression
mconcat (map (\x -> All (even x)) [2,4,6,7,8])All {getAll = False}
Example1 expression
All True <> memptyAll {getAll = True}

Constructors

Instances27Bounded, Eq, Data, Ord, Read, Show, …
  • Bounded AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Eq AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Data AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Ord AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Read AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Show AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Generic AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Semigroup AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • NFData AllDefined in deepseq-1.5.0.0 · Control.DeepSeq
  • Arbitrary AllDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • CoArbitrary AllDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • Function AllDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function
  • Binary AllDefined in binary-0.8.9.3 · Data.Binary.Class
  • Unbox AllDefined in vector-0.13.2.0 · Data.Vector.Unboxed.Base
  • Generic AllDefined in linear-generics-0.2.3 · Generics.Linear.Instances.Base · orphan
  • Monoid AllDefined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Monoid
  • Consumable AllDefined in linear-base-0.4.0 · Data.Unrestricted.Linear.Internal.Consumable
  • Dupable AllDefined in linear-base-0.4.0 · Data.Unrestricted.Linear.Internal.Dupable
  • Semigroup AllDefined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Movable AllDefined in linear-base-0.4.0 · Data.Unrestricted.Linear.Internal.Movable
  • Vector Vector AllDefined in vector-0.13.2.0 · Data.Vector.Unboxed.Base
  • MVector MVector AllDefined in vector-0.13.2.0 · Data.Vector.Unboxed.Base
  • type Rep All = D1 ('MetaData "All" "GHC.Internal.Data.Semigroup.Internal" "ghc-internal" 'True) (C1 ('MetaCons "All" 'PrefixI 'True) (S1 ('MetaSel ('Just "getAll") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)))Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • data MVector s AllDefined in vector-0.13.2.0 · Data.Vector.Unboxed.Base
  • data Vector AllDefined in vector-0.13.2.0 · Data.Vector.Unboxed.Base
  • type Rep All = D1 ('MetaData "All" "GHC.Internal.Data.Semigroup.Internal" "ghc-internal" 'True) (C1 ('MetaCons "All" 'PrefixI 'True) (S1 ('MetaSel ('Just "getAll") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)))Defined in linear-generics-0.2.3 · Generics.Linear.Instances.Base · orphan
newtypenewtype Any
#

Boolean monoid under disjunction (||).

Any x <> Any y = Any (x || y)
Examples
Example1 expression
Any True <> mempty <> Any FalseAny {getAny = True}
Example1 expression
mconcat (map (\x -> Any (even x)) [2,4,6,7,8])Any {getAny = True}
Example1 expression
Any False <> memptyAny {getAny = False}

Constructors

Instances27Bounded, Eq, Data, Ord, Read, Show, …
  • Bounded AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Eq AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Data AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Ord AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Read AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Show AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Generic AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Semigroup AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • NFData AnyDefined in deepseq-1.5.0.0 · Control.DeepSeq
  • Arbitrary AnyDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • CoArbitrary AnyDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Arbitrary
  • Function AnyDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function
  • Binary AnyDefined in binary-0.8.9.3 · Data.Binary.Class
  • Unbox AnyDefined in vector-0.13.2.0 · Data.Vector.Unboxed.Base
  • Generic AnyDefined in linear-generics-0.2.3 · Generics.Linear.Instances.Base · orphan
  • Monoid AnyDefined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Monoid
  • Consumable AnyDefined in linear-base-0.4.0 · Data.Unrestricted.Linear.Internal.Consumable
  • Dupable AnyDefined in linear-base-0.4.0 · Data.Unrestricted.Linear.Internal.Dupable
  • Semigroup AnyDefined in linear-base-0.4.0 · Data.Monoid.Linear.Internal.Semigroup
  • Movable AnyDefined in linear-base-0.4.0 · Data.Unrestricted.Linear.Internal.Movable
  • Vector Vector AnyDefined in vector-0.13.2.0 · Data.Vector.Unboxed.Base
  • MVector MVector AnyDefined in vector-0.13.2.0 · Data.Vector.Unboxed.Base
  • type Rep Any = D1 ('MetaData "Any" "GHC.Internal.Data.Semigroup.Internal" "ghc-internal" 'True) (C1 ('MetaCons "Any" 'PrefixI 'True) (S1 ('MetaSel ('Just "getAny") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)))Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • data MVector s AnyDefined in vector-0.13.2.0 · Data.Vector.Unboxed.Base
  • data Vector AnyDefined in vector-0.13.2.0 · Data.Vector.Unboxed.Base
  • type Rep Any = D1 ('MetaData "Any" "GHC.Internal.Data.Semigroup.Internal" "ghc-internal" 'True) (C1 ('MetaCons "Any" 'PrefixI 'True) (S1 ('MetaSel ('Just "getAny") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)))Defined in linear-generics-0.2.3 · Generics.Linear.Instances.Base · orphan
newtypenewtype First a
#

Beware that Data.Semigroup.First is different from Data.Monoid.First. The former simply returns the first value, so Data.Semigroup.First Nothing <> x = Data.Semigroup.First Nothing. The latter returns the first non-Nothing, thus Data.Monoid.First Nothing <> x = x.

Examples
Example1 expression
First 0 <> First 10First 0
Example1 expression
sconcat $ First 1 :| [ First n | n <- [2 ..] ]First 1

Constructors

Instances35Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
newtypenewtype Last a
#

Beware that Data.Semigroup.Last is different from Data.Monoid.Last. The former simply returns the last value, so x <> Data.Semigroup.Last Nothing = Data.Semigroup.Last Nothing. The latter returns the last non-Nothing, thus x <> Data.Monoid.Last Nothing = x.

Examples
Example1 expression
Last 0 <> Last 10Last {getLast = 10}
Example1 expression
sconcat $ Last 1 :| [ Last n | n <- [2..]]Last {getLast = * hangs forever *

Constructors

Instances35Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
newtypenewtype Dual a
#

The dual of a Monoid, obtained by swapping the arguments of (<>).

Dual a <> Dual b == Dual (b <> a)
Examples
Example1 expression
Dual "Hello" <> Dual "World"Dual {getDual = "WorldHello"}
Example1 expression
Dual (Dual "Hello") <> Dual (Dual "World")Dual {getDual = Dual {getDual = "HelloWorld"}}

Constructors

Instances39Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
newtypenewtype Sum a
#

Monoid under addition.

Sum a <> Sum b = Sum (a + b)
Examples
Example1 expression
Sum 1 <> Sum 2 <> memptySum {getSum = 3}
Example1 expression
mconcat [ Sum n | n <- [3 .. 9]]Sum {getSum = 42}

Constructors

Instances42Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
newtypenewtype Product a
#

Monoid under multiplication.

Product x <> Product y == Product (x * y)
Examples
Example1 expression
Product 3 <> Product 4 <> memptyProduct {getProduct = 12}
Example1 expression
mconcat [ Product n | n <- [2 .. 10]]Product {getProduct = 3628800}

Constructors

Instances42Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …