The class of semigroups (types with an associative binary operation).
Instances should satisfy the following:
You can alternatively define sconcat instead of (<>), in which case the laws are:
Methods
(<>) :: a -> a -> ainfixr 6An associative operation.
Examples
Example1 expression [1,2,3] <> [4,5,6][1,2,3,4,5,6]
Example1 expression Just [1, 2, 3] <> Just [4, 5, 6]Just [1,2,3,4,5,6]
Example1 expression putStr "Hello, " <> putStrLn "World!"Hello, World!
sconcat :: NonEmpty a -> aReduce a non-empty list with <>
The default definition should be sufficient, but this can be overridden for efficiency.
Examples
For the following examples, we will assume that we have:
Example1 expression import Data.List.NonEmpty (NonEmpty (..))Example1 expression sconcat $ "Hello" :| [" ", "Haskell", "!"]"Hello Haskell!"
Example1 expression sconcat $ Just [1, 2, 3] :| [Nothing, Just [4, 5, 6]]Just [1,2,3,4,5,6]
Example1 expression sconcat $ Left 1 :| [Right 2, Left 3, Right 4]Right 2
stimes :: Integral b => b -> a -> aRepeat a value
ntimes.The default definition will raise an exception for a multiplier that is
<= 0. This may be overridden with an implementation that is total. For monoids it is preferred to usestimesMonoid.By making this a member of the class, idempotent semigroups and monoids can upgrade this to execute in
\mathcal{O}(1)by pickingstimes = stimesIdempotentorstimes = stimesIdempotentMonoidrespectively.Examples
Example1 expression stimes 4 [1][1,1,1,1]
Example1 expression stimes 5 (putStr "hi!")hi!hi!hi!hi!hi!
Example1 expression stimes 3 (Right ":)")Right ":)"
Instances79Semigroup, …
Semigroup ByteArrayDefined in base-4.20.2.0 · Data.Array.ByteSemigroup BuilderDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.InternalSemigroup ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeSemigroup ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Lazy.InternalSemigroup ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalSemigroup VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalSemigroup AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalSemigroup EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.TypesSemigroup EventLifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.TypesSemigroup LifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.TypesSemigroup ExceptionContextDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception.ContextSemigroup OrderingDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup OsStringDefined in os-string-2.0.7 · System.OsString.Internal.TypesSemigroup PosixStringDefined in os-string-2.0.7 · System.OsString.Internal.TypesSemigroup WindowsStringDefined in os-string-2.0.7 · System.OsString.Internal.TypesSemigroup DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJSemigroup CalendarDiffDaysDefined in time-1.12.2 · Data.Time.Calendar.CalendarDiffDaysAdditive
Semigroup CalendarDiffTimeDefined in time-1.12.2 · Data.Time.LocalTime.Internal.CalendarDiffTimeAdditive
Semigroup StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonORs the flags.
Semigroup StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonORs the masks.
Semigroup ()Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonoid m => Semigroup (WrappedMonoid m)Defined in base-4.20.2.0 · Data.SemigroupSemigroup (FromMaybe b)Defined in base-4.20.2.0 · Data.Foldable1Semigroup (NonEmptyDList a)Defined in base-4.20.2.0 · Data.Foldable1Semigroup (Comparison a)Defined in base-4.20.2.0 · Data.Functor.ContravariantSemigroup (Equivalence a)Defined in base-4.20.2.0 · Data.Functor.ContravariantSemigroup (Predicate a)Defined in base-4.20.2.0 · Data.Functor.ContravariantSemigroup (First a)Defined in base-4.20.2.0 · Data.SemigroupSemigroup (Last a)Defined in base-4.20.2.0 · Data.SemigroupSemigroup (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup (First a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidSemigroup (Last a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidSemigroup (Endo a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalSemigroup (Doc a)Defined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJSemigroup [a]Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup a => Semigroup (JoinWith a)Defined in base-4.20.2.0 · Data.Foldable1Semigroup a => Semigroup (STM a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Conc.SyncSemigroup a => Semigroup (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentitySemigroup a => Semigroup (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.OrdSemigroup a => Semigroup (Dual a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalSemigroup a => Semigroup (Maybe a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup a => Semigroup (IO a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup a => Semigroup (Q a)Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxSemigroup a => Semigroup (a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup p => Semigroup (Par1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsBits a => Semigroup (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Semigroup (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Semigroup (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => Semigroup (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsThis constraint is arguably too strong. However, as some types (such as
Natural) have undefined complement, this is the only safe choice.Num a => Semigroup (Product a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalNum a => Semigroup (Sum a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalOrd a => Semigroup (Max a)Defined in base-4.20.2.0 · Data.SemigroupOrd a => Semigroup (Min a)Defined in base-4.20.2.0 · Data.SemigroupOrd a => Semigroup (Max a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsOrd a => Semigroup (Min a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils(Generic a, Semigroup (Rep a ())) => Semigroup (Generically a)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup (Either a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.EitherSemigroup (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxySemigroup (U1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup (V1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup a => Semigroup (Op a b)Defined in base-4.20.2.0 · Data.Functor.ContravariantSemigroup a => Semigroup (ST s a)Defined in ghc-internal-9.1003.0 · GHC.Internal.STSemigroup b => Semigroup (a -> b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base(Semigroup a, Semigroup b) => Semigroup (a, b)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseAlternative f => Semigroup (Alt f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalSemigroup (f p) => Semigroup (Rec1 f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup a => Semigroup (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstSemigroup a => Semigroup (Constant a b)Defined in transformers-0.6.1.1 · Data.Functor.Constant(Applicative f, Semigroup a) => Semigroup (Ap f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup c => Semigroup (K1 i c p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Semigroup (f a), Semigroup (g a)) => Semigroup (Product f g a)Defined in base-4.20.2.0 · Data.Functor.Product(Semigroup (f p), Semigroup (g p)) => Semigroup ((:*:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup (f (g a)) => Semigroup (Compose f g a)Defined in base-4.20.2.0 · Data.Functor.ComposeSemigroup (f (g p)) => Semigroup ((:.:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup (f p) => Semigroup (M1 i c f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base