Skip to content

Commit

Permalink
document implemented instances
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosh committed Feb 7, 2022
1 parent 99e51de commit c02c57f
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/data-structures/Either.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ error messages of type `A`.

## Typeclass instances

- `EitherAlternative`
- `EitherApplicative`
- `EitherApply`
- `EitherBifunctor`
- `EitherFoldable`
- `EitherFunctor`
- `EitherMonad`
- `EitherMonadThrow`
- `EitherTraversable`
- `JoinEitherSemigroup`
- `MeetEitherSemigroup`
- `ValidationApplicative`
- `ValidationApply`

### Semigroup

We define two instances of `Semigroup` for `Either`. The difference between the two lies on their behaviour when they
Expand Down
7 changes: 7 additions & 0 deletions docs/data-structures/IO.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ Representing a generic computation, the `IO` datatype given access to any possib

The `IO` data structure should be used whenever there is the need to interact with the external world, being it a
database, a user or a web api.

## Typeclass instances

- `IOApplicative`
- `IOApply`
- `IOFunctor`
- `IOMonad`
9 changes: 9 additions & 0 deletions docs/data-structures/Identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ unwrap :: Identity A -> A
## Interpretation as an effect

The `Identity` datatype actually describes the absence of effects.

## Typeclass instances

- `IdentityApplicative`
- `IdentityApply`
- `IdentityFoldable`
- `IdentityFunctor`
- `IdentityMonad`
- `IdentityTraversable`
10 changes: 10 additions & 0 deletions docs/data-structures/LinkedList.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ looking at a list as the possible values of a probabilistic variable.
This interpretation is consistent with the behaviour of the `Apply` and the `Monad` instance for a `LinkedList`. For
example, the `Apply` instance allows to apply a `LinkedList` of functions to a `LinkedList` of values; the result is the
`LinkedList` containing all the results of applying every function to every value.

## Typeclass instances

- `LinkedListApplicative`
- `LinkedListApply`
- `LinkedListFoldable`
- `LinkedListFunctor`
- `LinkedListMonad`
- `LinkedListMonoid`
- `LinkedListTraversable`
10 changes: 10 additions & 0 deletions docs/data-structures/Maybe.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ The `Maybe` datatype can be interpreted as a model to denote the possibility of

Its instances allow composing `Maybe` values as if the values were always there, managing the possibility of absence
under the hood.

## Typeclass instances

- `MaybeApplicative`
- `MaybeApply`
- `MaybeFoldable`
- `MaybeFunctor`
- `MaybeMonad`
- `MaybeMonadThrow`
- `MaybeTraversable`
8 changes: 8 additions & 0 deletions docs/data-structures/Pair.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ attached additional information to a value; this information could be metadata o

Pay attention that all the instances, except the `Bifunctor` one, work exclusively on the second component of the pair.
For example, if you map a pair, only the second component will be affected.

## Typeclass instances

- `PairApplicative`
- `PairApply`
- `PairBifunctor`
- `PairFunctor`
- `PairMonad`
7 changes: 7 additions & 0 deletions docs/data-structures/Reader.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ runReader :: (Reader<E, A>, E) -> A
## Interpretation as an effect

The `Reader` datatype allows modelling values and computation which depend on an environment.

## Typeclass instances

- `ReaderApplicative`
- `ReaderApply`
- `ReaderFunctor`
- `ReaderMonad`
7 changes: 7 additions & 0 deletions docs/data-structures/State.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ runState :: (State<S, A>, S) -> Pair<S, A>

The `State` data structure is used to model stateful computations in a pure fashion. A value of type `State<S, A>`
represents a stateful computation interacting with a state of type `S` and returning a value of type `A`.

## Typeclass instances

- `StateApplicative`
- `StateApply`
- `StateFunctor`
- `StateMonad`
4 changes: 4 additions & 0 deletions docs/typeclasses/Alternative.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ $alternative->apply($alternative->alt($f, $g), $x) == $alternative->alt($alterna
```php
$alternative->apply($alternative->empty(), $f) == $alternative->empty()
```

## Implemented instances

- `EitherAlternative`
12 changes: 12 additions & 0 deletions docs/typeclasses/Applicative.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,15 @@ $applicative->apply($applicative->pure($f), $applicative->pure($x)) == $applicat
```php
$applicative->apply($f, $applicative->pure($x)) == $applicative->apply(fn (callable $g) => $g($x), $f)
```

## Implemented instances

- `EitherApplicative`
- `ValidationApplicative`
- `IdentityApplicative`
- `IOApplicative`
- `LinkedListApplicative`
- `MaybeApplicative`
- `PairApplicative`
- `ReaderApplicative`
- `StateApplicative`
12 changes: 12 additions & 0 deletions docs/typeclasses/Apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,15 @@ application is associative
```php
$apply->apply($apply->apply($apply->map(fn ($f, $g) => fn ($x) => $f($g($x)), $a), $b), $c) == $apply->apply($a, $apply->apply($b, $c))
```

## Implemented instances

- `EitherApply`
- `ValidationApply`
- `IdentityApply`
- `IOApply`
- `LinkedListApply`
- `MaybeApply`
- `PairApply`
- `ReaderApply`
- `StateApply`
5 changes: 5 additions & 0 deletions docs/typeclasses/Bifunctor.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ $bifunctor->biMap(fn($x) => $x, fn($x) => $x, $a) == $a
```php
$bifunctor->biMap(fn($x) => $f($g($x)), fn($x) => $h($k($x)), $a) == $bifunctor->biMap(fn($x) => $f($x), fn($x) => $h($x), $bifunctor->biMap(fn($x) => $g($x), fn($x) => $k($x)), $a)
```

## Implemented instances

- `EitherBifunctor`
- `PairBifunctor`
7 changes: 7 additions & 0 deletions docs/typeclasses/Foldable.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ Its simplified type is
```
foldr :: ((A, B) -> B, B, T<A>) -> B
```

## Implemented instances

- `EitherFoldable`
- `IdentityFoldable`
- `LinkedListFoldable`
- `MaybeFoldable`
11 changes: 11 additions & 0 deletions docs/typeclasses/Functor.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ Mapping the composition of two functions or composing the mapping of those funct
```php
$functor->map(fn($x) => $f($g($x)), $y) == $functor->map(fn($x) => $f($x), $functor->map(fn($x) => $g($x), $y))
```

## Implemented instances

- `EitherFunctor`
- `IdentityFunctor`
- `IOApplyFunctor`
- `LinkedListFunctor`
- `MaybeFunctor`
- `PairFunctor`
- `ReaderFunctor`
- `StateFunctor`
11 changes: 11 additions & 0 deletions docs/typeclasses/Monad.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,14 @@ $monad->bind($a, fn($x) => $monad->pure($x)) == $a
```php
$monad->bind($a, fn($x) => $monad->bind($f($x), $g)) == $monad->bind($monad->bind($a, $g), $g)
```

## Implemented instances

- `EitherMonad`
- `IdentityMonad`
- `IOMonad`
- `LinkedListMonad`
- `MaybeMonad`
- `PairMonad`
- `ReaderMonad`
- `StateMonad`
5 changes: 5 additions & 0 deletions docs/typeclasses/MonadThrow.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ The `MonadThrow` typeclass should satisfy one addition laws with respect to the
```php
$monadThrow->bind($monadThrow->throwError($e), $f) == $monadThrow->throwError($e)
```

## Implemented instances

- `EitherMonadThrow`
- `MaybeMonadThrow`
4 changes: 4 additions & 0 deletions docs/typeclasses/Monoid.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ $monoid->append($a, $monoid->mempty()) == $a
```php
$monoid->append($monoid->mempty(), $a) == $a
```

## Implemented instances

- `LinkedListMonoid`
6 changes: 6 additions & 0 deletions docs/typeclasses/Semigroup.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ The only law associated to the `Semigroup` typeclass states that it should be as
```php
$semigroup->append($a, $semigroup->append($b, $c)) == $semigroup->append($semigroup->append($a, $b), $c)
```

## Implemented instances

- `JoinEitherSemigroup`
- `MeetEitherSemigroup`
- `LinkedListMonoid`
7 changes: 7 additions & 0 deletions docs/typeclasses/Traversable.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,10 @@ $traversable->traverse(new IdentityApplicative(), fn($x) => new Identity($x), $y
### Composition

// TODO

## Implemented instances

- `EitherTraversable`
- `IdentityTraversable`
- `LinkedListTraversable`
- `MaybeTraversable`

0 comments on commit c02c57f

Please sign in to comment.