-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters