Skip to content

Free Structures and Algebraic Data Types

Latest
Compare
Choose a tag to compare
@broomburgo broomburgo released this 23 May 07:27
77f2902

This release focuses on two main topics: free structures and algebraic data types.

Free structures

4 free algebraic structures were defined as typealiases of existing and brand new data structures, that is:

  • NonEmptyArray (brand new) -> FreeSemigroup;
  • Array -> FreeMonoid;
  • Multiset (a.k.a. Bag, brand new) -> FreeCommutativeMonoid;
  • Set -> FreeBoundedSemilattice.

A free representation for Semiring was also provided, with the type SetM (a Set where elements are monoids).

Algebraic data types

3 algebraic data types were added, that is, data types that exist only for combining other types in interesting ways, that is:

  • Product<A,B>, representing A and B at the same time;
  • Coproduct<A,B>, representing either A or B;
  • Inclusive<A,B>, representing one of the following:
    • only type A;
    • only type B;
    • both types A and B.

These types have definitions for the algebraic structures depending on the contained types: e.g. Product<A,B> is a Monoid if A and B are monoids.

Finally, the Function type was included among the algebraic data types.