monoid-subclasses: Subclasses of Monoid

[ algebra, bsd3, data, library, text ] [ Propose Tags ]

A hierarchy of subclasses of Monoid together with their instances for all data structures from base, containers, and text packages.

[Skip to Readme]


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS] 0.1, 0.1.1, 0.1.2, 0.2, 0.3, 0.3.1, 0.3.2, 0.3.3, 0.3.4,, 0.3.5, 0.3.6,,, 0.4,,,,, 0.4.1,,, 0.4.2,, 0.4.3,,, 0.4.4, 0.4.5, 0.4.6,, 1.0, 1.0.1, 1.1, 1.1.1, 1.1.2, 1.1.3, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.2.4,, 1.2.5
Change log
Dependencies base (>=4.6 && <4.11), bytestring (>=0.9 && <1.0), containers (>= && <0.6), primes (>=0.2 && <0.3), text (>=0.11 && <1.3), vector (>=0.9 && <0.13) [details]
License BSD-3-Clause
Copyright (c) 2013-2017 Mario Blažević
Author Mario Blažević
Maintainer Mario Blažević <>
Revised Revision 1 made by HerbertValerioRiedel at 2018-10-06T23:39:21Z
Category Data, Algebra, Text
Home page
Bug tracker
Source repo head: git clone
Uploaded by MarioBlazevic at 2017-08-03T04:13:51Z
Distributions Arch:, Debian:1.0.1, Fedora:1.2.3, LTSHaskell:, NixOS:, Stackage:1.2.5, openSUSE:
Reverse Dependencies 25 direct, 91 indirect [details]
Downloads 44771 total (370 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-08-03 [all 1 reports]

Readme for monoid-subclasses-0.4.4

[back to package description]


Subclasses of Monoid with a solid theoretical foundation and practical purposes

The monoid-subclasses package has been released on Hackage. The package defines several classes that are richer than monoids but less demanding than groups:

  • ReductiveMonoid provides the operator </> which acts as a partial inverse of the <> operator, i.e., Monoid.mappend.

  • CancellativeMonoid is a subclass of ReductiveMonoid that provides additional guarantees about the </> operation result:

    (a <> b) </> a == Just b
    (a <> b) </> b == Just a

    Every group (i.e., every Monoid a with the operation inverse :: a -> a) is a CancellativeMonoid where a </> b = Just (a <> inverse b) but not every CancellativeMonoid is a group.

  • GCDMonoid is a subclass of ReductiveMonoid that provides the gcd operation for getting the greatest common denominator for two given monoid values.

  • MonoidNull class provides the Boolean null operation that checks if the argument monoid is mempty.

  • FactorialMonoid class represents monoids that can be split up into irreducible factors.

That's the theoretical point of view. From the practical point of view, the main purpose of the monoid-subclasses package is similar to that of ListLike - to provide unifying abstractions for various monoidal data types in Haskell, primarily String, ByteString, and Text. All three types are already instances of the Monoid class. While that abstraction is useful for building sequences of data, it doesn't help with deconstructing them.

That being said, there are two major differences in the goals of ListLike and monoid-subclasses:

  • ListLike strives to reproduce the standard Data.List interface, whereas monoid-subclasses builds from deeper theoretical foundations; and
  • The monoid-subclasses implementation uses standard Haskell 2010, with the exception of two minor extensions which can be worked around if necessary.

The incremental-parser package provides one example of use of monoid-subclasses. Another example is picoparsec, a fork of attoparsec.

A more thorough description of the library can be found in the Haskell Symposium 2013 paper Adding Structure to Monoids