Skip to content

Commit

Permalink
Edit Laws.md s/Canonical/Canonicity/g
Browse files Browse the repository at this point in the history
  • Loading branch information
viercc committed May 8, 2021
1 parent 6adffb9 commit bf7e489
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Laws.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ These facts follow from the laws.
From the above laws, it can be proven that lawful `wither` is unique given
`traverse` and `mapMaybe`:
* **Canonical**
* **Canonicity**
```haskell
wither f = fmap catMaybes . traverse f
Expand Down Expand Up @@ -204,7 +204,7 @@ fmap catMaybes . traverse f = wither f

These two laws are equivalent to the above set of laws.

* **Canonical**
* **Canonicity**

```haskell
wither f = fmap catMaybes . traverse f
Expand All @@ -216,7 +216,7 @@ These two laws are equivalent to the above set of laws.
traverse f . catMaybes = fmap catMaybes . traverse (traverse f)
```

It's already showed that the original laws imply **Canonical**.
It's already showed that the original laws imply **Canonicity**.
They imply **Distributivity** too.

_Proof._
Expand All @@ -230,34 +230,34 @@ Compose . Identity . traverse f . catMaybes
= wither (Compose . Identity . traverse f)
-- (Compose . Identity) is an applicative transformation
= Compose . Identity . wither (traverse f)
-- Canonical is already proven equation
-- Canonicity is already proven equation
= Compose . Identity . fmap catMaybes . traverse (traverse f)

And (Compose . Identity) is isomorphism. We can conclude

traverse f . catMaybes = fmap catMaybes . traverse (traverse f)
```

Then let's do the other direction. **Canonical** + **Distributivity**,
Then let's do the other direction. **Canonicity** + **Distributivity**,
along with `Filterable` and `Traversable` laws,
prove all three of `Witherable` laws + **Conservation** + **Pure filter**.

_Proof._
```haskell
-- Naturality
n . wither f
-- Canonical
-- Canonicity
= n . fmap catMaybes . traverse f
-- n is natural transformation
= fmap catMaybes . n . traverse f
-- Naturality of traverse
= fmap catMaybes . traverse (n . f)
-- Canonical
-- Canonicity
= wither (n . f)

-- Conservation
wither (fmap Just . f)
-- Canonical
-- Canonicity
= fmap catMaybes . traverse (fmap Just . f)
= fmap catMaybes . fmap (fmap Just) . traverse f
= fmap (catMaybes . fmap Just) . traverse f
Expand All @@ -267,7 +267,7 @@ wither (fmap Just . f)

-- Pure filter
wither (Identity . f)
-- Canonical
-- Canonicity
= fmap catMaybes . traverse (Identity . f)
-- Traversable law, Identity
= fmap catMaybes . Identity . fmap f
Expand All @@ -283,7 +283,7 @@ wither (Identity . Just)

-- Composition
Compose . fmap (wither g) . wither f
-- Canonical
-- Canonicity
= Compose . fmap (fmap catMaybes . traverse g) . fmap catMaybes . traverse f
= Compose . fmap (fmap catMaybes) . fmap (traverse g . catMaybes) . traverse f
-- Distributivity
Expand All @@ -297,7 +297,7 @@ Compose . fmap (wither g) . wither f
= fmap (catMaybes . fmap join) . traverse (Compose . fmap (traverse g) . f)
= fmap catMaybes . fmap (fmap join) . traverse (Compose . fmap (traverse g) . f)
= fmap catMaybes . traverse (fmap join . Compose . fmap (traverse g) . f)
-- Canonical
-- Canonicity
= wither (Compose . fmap (fmap join . traverse g) . f)
-- Definition of witherMaybe
= wither (Compose . fmap (witherMaybe g) . f)
Expand Down

0 comments on commit bf7e489

Please sign in to comment.