Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit bf1d3d2

Browse files
committed
Docs
1 parent d111652 commit bf1d3d2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Module Data.Inject
44

5+
6+
This module defines a type class `Inject` which is useful
7+
when working with coproducts of functors.
8+
59
#### `Inject`
610

711
``` purescript
@@ -10,27 +14,39 @@ class Inject f g where
1014
prj :: forall a. g a -> Maybe (f a)
1115
```
1216

17+
The `Inject` class asserts a coproduct relationship between two functors.
18+
19+
Specifically, an instance `Inject f g` indicates that `g` is isomorphic to
20+
a coproduct of `f` and some third functor.
21+
22+
Laws:
23+
24+
- `prj g = Just f` if and only if `inj f = g`
1325

1426
#### `injectReflexive`
1527

1628
``` purescript
1729
instance injectReflexive :: Inject f f
1830
```
1931

32+
Any functor is isomorphic to the coproduct of itself with the
33+
constantly-`Void` functor.
2034

2135
#### `injectLeft`
2236

2337
``` purescript
2438
instance injectLeft :: Inject f (Coproduct f g)
2539
```
2640

41+
Left injection
2742

2843
#### `injectRight`
2944

3045
``` purescript
3146
instance injectRight :: (Inject f g) => Inject f (Coproduct h g)
3247
```
3348

49+
Right injection
3450

3551

3652

src/Data/Inject.purs

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
-- | This module defines a type class `Inject` which is useful
2+
-- | when working with coproducts of functors.
3+
14
module Data.Inject
25
( Inject
36
, inj, prj
@@ -7,18 +10,30 @@ import Data.Either (Either(..))
710
import Data.Functor.Coproduct (Coproduct(..), coproduct)
811
import Data.Maybe (Maybe(..))
912

13+
-- | The `Inject` class asserts a coproduct relationship between two functors.
14+
-- |
15+
-- | Specifically, an instance `Inject f g` indicates that `g` is isomorphic to
16+
-- | a coproduct of `f` and some third functor.
17+
-- |
18+
-- | Laws:
19+
-- |
20+
-- | - `prj g = Just f` if and only if `inj f = g`
1021
class Inject f g where
1122
inj :: forall a. f a -> g a
1223
prj :: forall a. g a -> Maybe (f a)
1324

25+
-- | Any functor is isomorphic to the coproduct of itself with the
26+
-- | constantly-`Void` functor.
1427
instance injectReflexive :: Inject f f where
1528
inj = id
1629
prj = Just
1730

31+
-- | Left injection
1832
instance injectLeft :: Inject f (Coproduct f g) where
1933
inj = Coproduct <<< Left
2034
prj = coproduct Just (const Nothing)
2135

36+
-- | Right injection
2237
instance injectRight :: (Inject f g) => Inject f (Coproduct h g) where
2338
inj = Coproduct <<< Right <<< inj
2439
prj = coproduct (const Nothing) prj

0 commit comments

Comments
 (0)