Skip to content

Commit 41f66a3

Browse files
committed
Merge remote-tracking branch 'yoneda/master' into topic/yoneda
2 parents fd5837e + e1f6878 commit 41f66a3

File tree

6 files changed

+110
-6
lines changed

6 files changed

+110
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.psci
2+
.psci_modules/
23
node_modules
34
bower_components
45
dist

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# Deprecation Notice
2-
3-
Please note that this library has been merged into [purescript-transformers](https://github.com/purescript-contrib/purescript-transformers).
1+
# purescript-free

bower.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"dist"
1414
],
1515
"dependencies": {
16-
"purescript-transformers": "0.1.2",
17-
"purescript-either": "0.1.3"
16+
"purescript-control": "0.2.1",
17+
"purescript-either": "0.1.3",
18+
"purescript-exists": "*",
19+
"purescript-transformers": "0.1.2"
1820
}
1921
}

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ gulp.task('clean', function(){
3333
);
3434
});
3535

36-
gulp.task('examples', ['clean'], function(){
36+
gulp.task('examples', function(){
3737
return (
3838
gulp.src([config.purescript.examples].concat(config.purescript.src)).
3939
pipe(plumber()).

src/Data/Coyoneda.purs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module Data.Coyoneda
2+
( Coyoneda(..)
3+
, Natural(..)
4+
, coyoneda
5+
, liftCoyoneda
6+
, lowerCoyoneda
7+
, liftCoyonedaT
8+
, liftCoyonedaTF
9+
) where
10+
11+
import Data.Exists
12+
13+
import Control.Comonad
14+
import Control.Extend
15+
import Control.Monad.Trans
16+
17+
newtype CoyonedaF f a i = CoyonedaF { k :: i -> a, fi :: f i }
18+
19+
newtype Coyoneda f a = Coyoneda (Exists (CoyonedaF f a))
20+
21+
type Natural f g = forall a. f a -> g a
22+
23+
instance functorCoyoneda :: Functor (Coyoneda f) where
24+
(<$>) f (Coyoneda e) = runExists (\(CoyonedaF v) -> coyoneda (f <<< v.k) v.fi) e
25+
26+
instance applyCoyoneda :: (Apply f) => Apply (Coyoneda f) where
27+
(<*>) f g = liftCoyoneda $ lowerCoyoneda f <*> lowerCoyoneda g
28+
29+
instance applicativeCoyoneda :: (Applicative f) => Applicative (Coyoneda f) where
30+
pure = liftCoyoneda <<< pure
31+
32+
instance bindCoyoneda :: (Bind f) => Bind (Coyoneda f) where
33+
(>>=) (Coyoneda e) k = liftCoyoneda $ runExists (\(CoyonedaF v) -> v.fi >>= lowerCoyoneda <<< k <<< v.k) e
34+
35+
instance monadCoyoneda :: (Monad f) => Monad (Coyoneda f)
36+
37+
instance monadTransCoyoneda :: MonadTrans Coyoneda where
38+
lift = liftCoyoneda
39+
40+
instance extendCoyoneda :: (Extend w) => Extend (Coyoneda w) where
41+
(<<=) f (Coyoneda e) = runExists (\(CoyonedaF w) -> liftCoyoneda $ f <<< coyoneda w.k <<= w.fi) e
42+
43+
instance comonadCoyoneda :: (Comonad w) => Comonad (Coyoneda w) where
44+
extract (Coyoneda e) = runExists (\(CoyonedaF w) -> w.k $ extract w.fi) e
45+
46+
coyoneda :: forall f a b. (a -> b) -> f a -> Coyoneda f b
47+
coyoneda k fi = Coyoneda $ mkExists $ CoyonedaF { k: k, fi: fi }
48+
49+
liftCoyoneda :: forall f a. f a -> Coyoneda f a
50+
liftCoyoneda fa = Coyoneda $ mkExists $ CoyonedaF { k: id, fi: fa }
51+
52+
lowerCoyoneda :: forall f a. (Functor f) => Coyoneda f a -> f a
53+
lowerCoyoneda (Coyoneda e) = runExists (\(CoyonedaF v) -> v.k <$> v.fi) e
54+
55+
liftCoyonedaT :: forall f g. Natural f g -> Natural (Coyoneda f) (Coyoneda g)
56+
liftCoyonedaT nat (Coyoneda e) = runExists (\(CoyonedaF v) -> coyoneda v.k (nat v.fi)) e
57+
58+
liftCoyonedaTF :: forall f g. (Functor g) => Natural f g -> Natural (Coyoneda f) g
59+
liftCoyonedaTF nat = lowerCoyoneda <<< liftCoyonedaT nat

src/Data/Yoneda.purs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module Data.Yoneda
2+
( Yoneda(..)
3+
, runYoneda
4+
, liftYoneda
5+
, lowerYoneda
6+
) where
7+
8+
import Control.Comonad
9+
import Control.Extend
10+
import Control.Monad.Trans
11+
12+
newtype Yoneda f a = Yoneda (forall b. (a -> b) -> f b)
13+
14+
instance functorYoneda :: Functor (Yoneda f) where
15+
(<$>) f m = Yoneda (\k -> runYoneda m (k <<< f))
16+
17+
instance applyYoneda :: (Apply f) => Apply (Yoneda f) where
18+
(<*>) (Yoneda f) (Yoneda g) = Yoneda (\k -> (f $ (<<<) k) <*> g id)
19+
20+
instance applicativeYoneda :: (Applicative f) => Applicative (Yoneda f) where
21+
pure = liftYoneda <<< pure
22+
23+
instance bindCoyoneda :: (Bind f) => Bind (Yoneda f) where
24+
(>>=) (Yoneda f) g = Yoneda (\k -> f id >>= \a -> runYoneda (g a) k)
25+
26+
instance monadYoneda :: (Monad f) => Monad (Yoneda f)
27+
28+
instance monadTransYoneda :: MonadTrans Yoneda where
29+
lift = liftYoneda
30+
31+
instance extendYoneda :: (Extend w) => Extend (Yoneda w) where
32+
(<<=) f (Yoneda w) = Yoneda (\k -> k <<< f <<< liftYoneda <<= w id)
33+
34+
instance comonadYoneda :: (Comonad w) => Comonad (Yoneda w) where
35+
extract = extract <<< lowerYoneda
36+
37+
runYoneda :: forall f a b. Yoneda f a -> (a -> b) -> f b
38+
runYoneda (Yoneda f) k = f k
39+
40+
liftYoneda :: forall f a. (Functor f) => f a -> Yoneda f a
41+
liftYoneda m = Yoneda (\k -> k <$> m)
42+
43+
lowerYoneda :: forall f a. Yoneda f a -> f a
44+
lowerYoneda (Yoneda k) = k id

0 commit comments

Comments
 (0)