fun_land v0.5.0 FunLand.Combinable behaviour

If an operation is can combine two elements, and there is a clearly defined neutral that can be used to keep the same element when used on an element.

In Category Theory, something that is Combinable is called a Monoid.

Examples

integers-addition with 0 as neutral element forms a Monoid, also known as the Sum. integer-multiplication with 1 as neutral element forms a Monoid, also known as the Product.

Fruit Salad Example

Bowls that you can use to mix fruits in, are a monoid:

The combine operation would be to put the fruits from Bowl A into Bowl B, keeping that one. The neutral operation would be to take an emtpy bowl.

As can be seen, this follows the Combinable laws:

  • left-identity: putting the fruits from an empty bowl into a bowl with appljes, would be the same as doing nothing (you still have ‘a bowl with apples’)
  • right-identity: putting the fruits from a bowl of apples into an empty bowl, would be the same as doing nothing (you still have ‘a bowl with apples’)

Summary

Types

Functions

neutral(combinable)

Callbacks

neutral()

Specs

neutral :: combinable(a) when a: any