Anything that associates

Version on this page:
LTS Haskell 22.23:0.20
Stackage Nightly 2024-05-28:0.20
Latest on Hackage:0.20

See all snapshots semigroups appears in

BSD-3-Clause licensed by Edward A. Kmett
Maintained by Edward A. Kmett
This version can be pinned in stack with:semigroups-,3598

Module documentation for

  • Data
    • Data.List
      • Data.List.NonEmpty
    • Data.Semigroup


Build Status

Haskellers are usually familiar with monoids. A monoid has an appending operation <> or mappend and an identity element mempty. A Semigroup has an append <>, but does not require an mempty element. A Monoid can be made a Semigroup with just instance Semigroup MyMonoid

More formally, a semigroup is an algebraic structure consisting of a set together with an associative binary operation. A semigroup generalizes a monoid in that there might not exist an identity element. It also (originally) generalized a group (a monoid with all inverses) to a type where every element did not have to have an inverse, thus the name semigroup.

Semigroups appear all over the place, except in the Haskell Prelude, so they are packaged here.

Contact Information

Contributions and bug reports are welcome!

Please feel free to contact me through github or on the #haskell IRC channel on

-Edward Kmett


  • Bumped deepseq version bound for GHC 7.10 compatibility.


  • times1p and timesN are now reduced to accepting only a Natural argument. Whole doesn’t exist in GHC 7.10’s Numeric.Natural, and nats version 1 has removed support for the class.


  • Use Data.Coerce.coerce on GHC 7.8+ to reduce the number of eta-expansions in the resulting core.
  • Avoid conflict with pending Foldable.length in base.


  • instance NFData a => NFData (NonEmpty a)
  • Added NFData instances for the types in Data.Semigroup


  • Fixed a Trustworthiness problem for GHC 7.8+


  • Nathan van Doorn fixed a number of embarassing bugs in the Enum instances.


  • instance IsList NonEmpty


  • Allow for manual removal of dependencies to support advanced sandbox users who explicitly want to avoid compiling certain dependencies they know they aren’t using.

    We will fix bugs caused by any combination of these package flags, but the API of the package should be considered the default build configuration with all of the package dependency flags enabled.

  • Will now build as full-fledged Safe Haskell if you configure with -f-hashable.

  • Added some missing Generic/Generic/Hashable instances

  • Generic support requires ghc-prim on GHC 7.4.


  • Added instances for ‘Generic’, ‘Foldable’, ‘Traversable’, ‘Enum’, ‘Functor’, ‘Hashable’, ‘Applicative’, ‘Monad’ and ‘MonadFix’


  • Vastly widened the dependency bound on text and bytestring.


  • Updated to support the new version of text.
  • Added transpose, sortBy and sortWith.


  • Added an instance for Const r.
  • Added some1


  • Added the missing instance for HashSet.


  • Added support for unordered-containers, bytestring and text.


  • Added a DefaultSignature for (<>) in terms of mappend.


  • Added timesN.


  • Moved Numeric.Natural to a separate nats package.