MyNixOS website logo
Description

Subclasses of Monoid.

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

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

Metadata

Version

1.2.5.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows