Skip to content

Commit 9d5c445

Browse files
committed
Started with some comonad transformers.
1 parent 8de108b commit 9d5c445

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

docs/Module.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# Module Documentation
22

3+
## Module Control.Comonad.Env.Trans
4+
5+
### Types
6+
7+
newtype EnvT e w a where
8+
EnvT :: Tuple e (w a) -> EnvT e w a
9+
10+
11+
### Type Class Instances
12+
13+
instance extendEnvT :: (Extend w) => Extend (EnvT e w)
14+
15+
instance functorEnvT :: (Functor w) => Functor (EnvT e w)
16+
17+
18+
### Values
19+
20+
runEnvT :: forall e w a. EnvT e w a -> Tuple e (w a)
21+
22+
23+
## Module Control.Comonad.Trans
24+
25+
### Type Classes
26+
27+
class ComonadTrans f where
28+
lower :: forall w a. (Comonad w) => f w a -> w a
29+
30+
331
## Module Control.Monad.Cont.Class
432

533
### Type Classes
@@ -35,7 +63,7 @@
3563

3664
instance applicativeContT :: (Functor m, Monad m) => Applicative (ContT r m)
3765

38-
instance appluContT :: (Functor m, Monad m) => Apply (ContT r m)
66+
instance applyContT :: (Functor m, Monad m) => Apply (ContT r m)
3967

4068
instance bindContT :: (Monad m) => Bind (ContT r m)
4169

@@ -109,9 +137,9 @@
109137

110138
instance alternativeErrorT :: (Monad m, Error e) => Alternative (ErrorT e m)
111139

112-
instance applicativeErrorT :: (Functor m, Monad m) => Applicative (ErrorT e m)
140+
instance applicativeErrorT :: (Applicative m) => Applicative (ErrorT e m)
113141

114-
instance applyErrorT :: (Functor m, Monad m) => Apply (ErrorT e m)
142+
instance applyErrorT :: (Apply m) => Apply (ErrorT e m)
115143

116144
instance bindErrorT :: (Monad m, Error e) => Bind (ErrorT e m)
117145

src/Control/Comonad/Env/Trans.purs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Control.Comonad.Env.Trans where
2+
3+
import Control.Comonad
4+
import Control.Extend
5+
import Data.Tuple
6+
7+
newtype EnvT e w a = EnvT (Tuple e (w a))
8+
9+
runEnvT :: forall e w a. EnvT e w a -> Tuple e (w a)
10+
runEnvT (EnvT x) = x
11+
12+
instance functorEnvT :: (Functor w) => Functor (EnvT e w) where
13+
(<$>) f (EnvT (Tuple e x)) = EnvT $ Tuple e (f <$> x)
14+
15+
instance extendEnvT :: (Extend w) => Extend (EnvT e w) where
16+
(<<=) f (EnvT (Tuple e x)) = EnvT $ Tuple e (f <$> ((Tuple e >>> EnvT) <<= x))

src/Control/Comonad/Trans.purs

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

0 commit comments

Comments
 (0)