Skip to content

Commit fe8fd04

Browse files
committed
Merge pull request #10 from joneshf/master
Added Comonad/Extend.
2 parents 6fa92ca + 7485be9 commit fe8fd04

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,38 @@ If you are have a conflict between `<|>` in `Prelude` and `Control.Alt` please u
6262
join :: forall a m. (Bind m) => m (m a) -> m a
6363

6464

65+
## Module Control.Comonad
66+
67+
### Type Classes
68+
69+
class (Extend w) <= Comonad w where
70+
extract :: forall a. w a -> a
71+
72+
73+
## Module Control.Extend
74+
75+
### Type Classes
76+
77+
class (Functor w) <= Extend w where
78+
(<<=) :: forall b a. (w a -> b) -> w a -> w b
79+
80+
81+
### Type Class Instances
82+
83+
instance extendArr :: (Semigroup w) => Extend (Prim.Function w)
84+
85+
86+
### Values
87+
88+
(=<=) :: forall b a w c. (Extend w) => (w b -> c) -> (w a -> b) -> w a -> c
89+
90+
(=>=) :: forall b a w c. (Extend w) => (w a -> b) -> (w b -> c) -> w a -> c
91+
92+
(=>>) :: forall b a w. (Extend w) => w a -> (w a -> b) -> w b
93+
94+
duplicate :: forall a w. (Extend w) => w a -> w (w a)
95+
96+
6597
## Module Control.Lazy
6698

6799
### Type Classes

src/Control/Comonad.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Control.Comonad where
2+
3+
import Control.Extend
4+
5+
class (Extend w) <= Comonad w where
6+
extract :: forall a. w a -> a

src/Control/Extend.purs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Control.Extend where
2+
3+
infixl 1 =>>
4+
infixr 1 <<=
5+
infixr 1 =>=
6+
infixr 1 =<=
7+
8+
class (Functor w) <= Extend w where
9+
(<<=) :: forall b a. (w a -> b) -> w a -> w b
10+
11+
instance extendArr :: (Semigroup w) => Extend ((->) w) where
12+
(<<=) f g w = f \w' -> g (w <> w')
13+
14+
(=>>) :: forall b a w. (Extend w) => w a -> (w a -> b) -> w b
15+
(=>>) w f = f <<= w
16+
17+
(=>=) :: forall b a w c. (Extend w) => (w a -> b) -> (w b -> c) -> w a -> c
18+
(=>=) f g w = g (f <<= w)
19+
20+
(=<=) :: forall b a w c. (Extend w) => (w b -> c) -> (w a -> b) -> w a -> c
21+
(=<=) f g w = f (g <<= w)
22+
23+
duplicate :: forall a w. (Extend w) => w a -> w (w a)
24+
duplicate w = id <<= w

0 commit comments

Comments
 (0)