# monoid-subclasses

Subclasses of Monoid https://github.com/blamario/monoid-subclasses/

 Version on this page: 0.4.6.1 LTS Haskell 14.21: 0.4.6.1 Stackage Nightly 2020-01-21: 1.0@rev:1 Latest on Hackage: 1.0.1

See all snapshots `monoid-subclasses` appears in

Maintained by

#### Module documentation for 0.4.6.1

This version can be pinned in stack with:`monoid-subclasses-0.4.6.1@sha256:a9a685021bb18ed969340058f66319c302fd0740333c446fca926417ef3ba2d4,2043`

# monoid-subclasses

### 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

## Version 0.4.6.1

Bumped the containers dependency upper bounds

## Version 0.4.6

Added the Semigroup instances to fix the compilation errors with base-4.11

## Version 0.4.4

Fixed boundary condition bugs in ByteStringUTF8 uncovered by a new version of QuickCheck

## Version 0.4.3.2

Fixed compilation errors with GHC 7.8.4 and older

## Version 0.4.3.1

Bumped the vector dependency upper bounds

## Version 0.4.3

• Added instances for 3- and 4-tuples
• Re-implemented Concat as an own data type, dropping Seq

## Version 0.4.2.1

• Fixed compilation problems with GHC 8 and containers-0.5.7
• Fixed compilation problems with GHC 8 and containers-0.5.7
• Merge pull request #10 from mgiles: minor typo in FactorialMonoid laws

## Version 0.4.2

• Fixed a bug in splitAt implementation for ByteStringUTF8
• Removed the overzealous assertions from ByteStringUTF8

## Version 0.4.1.2

Removing accidental reference to Instances.Markup module

## Version 0.4.1.1

• Bumped the vector dependency upper bounds
• Removed GHC-prof-options from the cabal file

## Version 0.4.1

• Changed the Prelude imports to enable compilation with GHC 7.4
• Added the toString method to TextualMonoid class
• Importing Text.Show.Functions to avoid overlapping instances
• Eliminated the redundant import warnings from GHC 7.10.1

## Version 0.4.0.4

• Added -Wall GHC option and eliminated almost all the warnings
• Fixed a bug in the Textual instance of ByteStringUTF8

## Version 0.4.0.3

• Excluding the imports of foldMap from Prelude

## Version 0.4.0.2

• Added more tests and fixed a bug in Stateful
• Fixed a bug in Positioned.span_
• Optimized the Stateful data type

## Version 0.3.6.2

• Added a bunch of pragmas

## Version 0.3.6

• Deprecated all the inject functions
• Registered the new Stateful module

## Version 0.3.4.1

Accommodating the text-1.0 release

• Introduced the function ByteStringUTF8.decode
• Removed the utf-string dependency
• Replaced the utf-string import by a more efficient UTF-8 encoding

## Version 0.3.1

• Added the Data.Monoid.Instances.Concat module and tests
• Added the StableFactorialMonoid subclass of FactorialMonoid
• Added more instances for ()

## Version 0.3

Added the CommutativeMonoid class at the root of the Cancellative classes

## Version 0.2

• Added TextualMonoid instances for Seq Char and Vector Char
• Renamed the FactorialMonoid method map to foldMap in keeping with Foldable

## Version 0.1.2

Optimizations of the default Factorial methods and of the ButeStringUTF8 instances

## Version 0.1

Initial release

Depends on 6 packages(full list with versions):
Used by 2 packages in lts-14.20(full list with versions):