Skip to content

Commit

Permalink
docs for Monoid
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosh committed Feb 7, 2022
1 parent eaf4e40 commit 99e51de
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/typeclasses/Monoid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Monoid

A `Monoid` is a `Semigroup` with an identity element.

## Parent

The `Monoid` typeclass extends the `Semigroup` typeclass.

## API

The `Monoid` typeclass adds e single method to the `Semigroup` typeclass, providing the ability to retrieve the identity
element for the associative operation.

```php
interface Monoid extends Semigroup
{
/**
* @return A
*/
public function mempty();
}
```

Its simplified type is

```
mempty :: () -> A
```

## Laws

The `Monoid` laws ensure that the element returned by `mempty` is in fact the identity of the associative operation.

### Right identity

```php
$monoid->append($a, $monoid->mempty()) == $a
```

### Left identity

```php
$monoid->append($monoid->mempty(), $a) == $a
```
2 changes: 2 additions & 0 deletions src/Typeclass/Monoid.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Marcosh\LamPHPda\Typeclass;

/**
* @see https://github.com/marcosh/lamphpda/tree/master/docs/typeclasses/Monoid.md
*
* @template-covariant A
*
* @extends Semigroup<A>
Expand Down

0 comments on commit 99e51de

Please sign in to comment.