-
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
41 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,39 @@ | ||
# Semigroup | ||
|
||
A `Semigroup` instance provides a way to combine two things of the same type to create another instance of the same | ||
type. | ||
|
||
## API | ||
|
||
The `Semigroup` typeclass exposes a method `append`, which requires two elements of the same type `A` to produce another | ||
element of type `A`. | ||
|
||
```php | ||
interface Semigroup | ||
{ | ||
/** | ||
* @param A $a | ||
* @param A $b | ||
* @return A | ||
* | ||
* @psalm-pure | ||
*/ | ||
public function append($a, $b); | ||
} | ||
``` | ||
|
||
It simplified type is | ||
|
||
``` | ||
append :: (A, A) -> A | ||
``` | ||
|
||
## Laws | ||
|
||
The only law associated to the `Semigroup` typeclass states that it should be associative. | ||
|
||
### Associativity | ||
|
||
```php | ||
$semigroup->append($a, $semigroup->append($b, $c)) == $semigroup->append($semigroup->append($a, $b), $c) | ||
``` |
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