This repository was archived by the owner on Oct 4, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 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
1729instance 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
2438instance injectLeft :: Inject f (Coproduct f g)
2539```
2640
41+ Left injection
2742
2843#### ` injectRight `
2944
3045``` purescript
3146instance injectRight :: (Inject f g) => Inject f (Coproduct h g)
3247```
3348
49+ Right injection
3450
3551
3652
Original file line number Diff line number Diff line change 1+ -- | This module defines a type class `Inject` which is useful
2+ -- | when working with coproducts of functors.
3+
14module Data.Inject
25 ( Inject
36 , inj , prj
@@ -7,18 +10,30 @@ import Data.Either (Either(..))
710import Data.Functor.Coproduct (Coproduct (..), coproduct )
811import 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`
1021class 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.
1427instance injectReflexive :: Inject f f where
1528 inj = id
1629 prj = Just
1730
31+ -- | Left injection
1832instance injectLeft :: Inject f (Coproduct f g ) where
1933 inj = Coproduct <<< Left
2034 prj = coproduct Just (const Nothing )
2135
36+ -- | Right injection
2237instance injectRight :: (Inject f g ) => Inject f (Coproduct h g ) where
2338 inj = Coproduct <<< Right <<< inj
2439 prj = coproduct (const Nothing ) prj
You can’t perform that action at this time.
0 commit comments