Skip to content

Commit 7e25f63

Browse files
committed
Added Extend and Comonad.
1 parent 1c28012 commit 7e25f63

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,40 @@
3434
join :: forall a m. (Bind m) => m (m a) -> m a
3535

3636

37+
## Module Control.Comonad
38+
39+
### Type Classes
40+
41+
class (Extend w) <= Comonad w where
42+
extract :: forall a. w a -> a
43+
44+
45+
## Module Control.Extend
46+
47+
### Type Classes
48+
49+
class (Functor w) <= Extend w where
50+
(<<=) :: forall b a. (w a -> b) -> w a -> w b
51+
52+
53+
### Type Class Instances
54+
55+
instance extendArr :: (Semigroup w) => Extend (Prim.Function w)
56+
57+
instance extendArray :: Extend Prim.Array
58+
59+
60+
### Values
61+
62+
(=<=) :: forall b a w c. (Extend w) => (w b -> c) -> (w a -> b) -> w a -> c
63+
64+
(=>=) :: forall b a w c. (Extend w) => (w a -> b) -> (w b -> c) -> w a -> c
65+
66+
(=>>) :: forall b a w. (Extend w) => w a -> (w a -> b) -> w b
67+
68+
duplicate :: forall a w. (Extend w) => w a -> w (w a)
69+
70+
3771
## Module Control.Monad
3872

3973
### Values

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)