monoid-subclasses: Subclasses of Monoid

[ algebra, bsd3, data, library, text ] [ Propose Tags ] [ Report a vulnerability ]
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.4.1, 0.3.5, 0.3.6, 0.3.6.1, 0.3.6.2, 0.4, 0.4.0.1, 0.4.0.2, 0.4.0.3, 0.4.0.4, 0.4.1, 0.4.1.1, 0.4.1.2, 0.4.2, 0.4.2.1, 0.4.3, 0.4.3.1, 0.4.3.2, 0.4.4, 0.4.5, 0.4.6, 0.4.6.1, 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.4.1, 1.2.5, 1.2.5.1
Change log CHANGELOG.md
Dependencies base (>=4.9 && <5), bytestring (>=0.9 && <1.0), commutative-semigroups (>=0.1 && <0.3), containers (>=0.5.7.0 && <0.8), primes (>=0.2 && <0.3), text (>=0.11 && <1.3 || >=2.0 && <2.2), vector (>=0.12 && <0.14) [details]
Tested with ghc ==9.0.1, ghc ==8.10.4, ghc ==8.8.4, ghc ==8.6.5, ghc ==8.4.4, ghc ==8.2.2, ghc ==8.0.2
License BSD-3-Clause
Copyright (c) 2013-2024 Mario Blažević
Author Mario Blažević
Maintainer Mario Blažević <blamario@protonmail.com>
Category Data, Algebra, Text
Home page https://github.com/blamario/monoid-subclasses/
Bug tracker https://github.com/blamario/monoid-subclasses/issues
Source repo head: git clone https://github.com/blamario/monoid-subclasses
Uploaded by MarioBlazevic at 2024-05-18T14:59:00Z
Distributions Arch:1.2.5.1, Debian:1.0.1, Fedora:1.2.3, LTSHaskell:1.2.5.1, NixOS:1.2.5.1, Stackage:1.2.5.1, openSUSE:1.2.5.1
Reverse Dependencies 26 direct, 93 indirect [details]
Downloads 47197 total (335 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 2024-05-18 [all 1 reports]

Readme for monoid-subclasses-1.2.5.1

[back to package description]

monoid-subclasses

Subclasses of Semigroup and 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 semigroups and monoids but less demanding than groups:

  • Reductive provides the operator </> which acts as a partial inverse of the semigroup <> operator.

  • Cancellative is a subclass of Reductive 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 cancellative monoid where a </> b = Just (a <> inverse b) but not every Cancellative monoid is a group.

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

  • LCMMonoid is a subclass of Reductive and Monoid that provides the lcm operation for getting the least common multiple for two given monoid values.

  • Monus provides the <\> monus operation. The set difference is one familiar instance of this operation.

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

  • Factorial and FactorialMonoid classes represent semigroups and 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 can serve as a compact example of a parser library that can be applied to different input types thanks to monoid-subclasses. There is also picoparsec, a fork of attoparsec, and the heavy-duty grammatical-parsers library.

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