package alg_structs

  1. Overview
  2. Docs

Module Alg_structs.MonoidSource

An interface for a type with a binary, associative operator over it and a privileged unit value.

A Monoid is a Semigroup enriched an identity element, called unit.

Some well known monoids are

  • The integers under addition
  1. type t = int
  2. op = (+)
  3. unit = 0
  • The integers under multiplication
  1. type t = int
  2. op = ( * )
  3. unit = 1
  • Strings under concatenation
  1. type t = string
  2. op = (^)
  3. unit = ""

Seed

Sourcemodule type Seed = sig ... end

The Seed needed to generate an implementation of Monoid for the type t

Interface

Sourcemodule type S = sig ... end

A monoid is a set of objects with an associative binary operation over it and a privileged unit element that acts as an identity.

Laws

Sourcemodule Law (M : S) : sig ... end

Law notes the laws that should be obeyed by any instantiation of Monoid in the form of predicates that should hold true for any arguments of the appropriate type.

Constructors

Module functors for creating implementations of Monoid

Sourcemodule Make (Seed : Seed) : S with type t = Seed.t

Make S is a implementation of Monoid grown from the implementation of the Seed.

Sourceval make : 'a -> ('a -> 'a -> 'a) -> (module S with type t = 'a)

make (unit : t) (op : t -> t -> t) is an implementation of Monoid over the type t with the given unit and op

Sourceval of_semigroup : (module Semigroup.S with type t = 'a) -> 'a -> (module S with type t = 'a)

of_semigroup semi unit forms an implementation of Monoid by enriching the give semigroup semi with the unit

Implementations

Sourcemodule Bool : sig ... end

Monoids over bool

Sourcemodule Int : sig ... end

Monoids over int

Sourcemodule Option : sig ... end

Semigroups over option types

Sourcemodule Endo : sig ... end
Sourcemodule Dual : sig ... end
OCaml

Innovation. Community. Security.