Skip to content
This repository was archived by the owner on May 24, 2018. It is now read-only.

Commit 0c53abe

Browse files
committed
Merge pull request #2 from purescript-contrib/profunctor
Make arrows profunctors
2 parents 754c298 + c01d6a7 commit 0c53abe

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

bower.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "purescript-arrows",
33
"homepage": "https://github.com/purescript-contrib/purescript-arrows",
44
"authors": [
5-
"Phil Freeman <[email protected]>"
5+
"Phil Freeman <[email protected]>",
6+
"Gary Burgess <[email protected]>"
67
],
78
"description": "Type classes for Arrows",
89
"keywords": [
@@ -21,6 +22,7 @@
2122
"package.json"
2223
],
2324
"dependencies": {
24-
"purescript-tuples": "*"
25+
"purescript-tuples": "~0.2.3",
26+
"purescript-profunctor": "~0.0.2"
2527
}
2628
}

docs/Module.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,65 @@
44

55
### Type Classes
66

7-
class (Category a) <= Arrow a where
7+
8+
class (Category a, Strong a) <= Arrow a where
9+
810
arr :: forall b c. (b -> c) -> a b c
9-
first :: forall b c d. a b c -> a (Tuple b d) (Tuple c d)
11+
1012

1113
class ArrowPlus a where
14+
1215
(<+>) :: forall b c. a b c -> a b c -> a b c
1316

17+
1418
class ArrowZero a where
19+
1520
azero :: forall b c. a b c
1621

1722

1823
### Type Class Instances
1924

25+
2026
instance arrowFunction :: Arrow Prim.Function
2127

2228

2329
### Values
2430

31+
2532
(&&&) :: forall a b b' c c'. (Arrow a) => a b c -> a b c' -> a b (Tuple c c')
2633

27-
(***) :: forall a b b' c c'. (Arrow a) => a b c -> a b' c' -> a (Tuple b b') (Tuple c c')
2834

29-
second :: forall a b c d. (Arrow a) => a b c -> a (Tuple d b) (Tuple d c)
35+
(***) :: forall a b b' c c'. (Arrow a) => a b c -> a b' c' -> a (Tuple b b') (Tuple c c')
3036

3137

3238
## Module Control.Arrow.Kleisli
3339

3440
### Types
3541

42+
3643
newtype Kleisli m a b where
37-
Kleisli :: a -> m b -> Kleisli m a b
44+
Kleisli :: (a -> m b) -> Kleisli m a b
3845

3946

4047
### Type Class Instances
4148

49+
4250
instance arrowKleisli :: (Monad m) => Arrow (Kleisli m)
4351

52+
4453
instance categoryKleisli :: (Monad m) => Category (Kleisli m)
4554

55+
56+
instance profunctorKleisli :: (Functor f) => Profunctor (Kleisli f)
57+
58+
4659
instance semigroupoidKleisli :: (Monad m) => Semigroupoid (Kleisli m)
4760

4861

62+
instance strongKleisli :: (Monad m) => Strong (Kleisli m)
63+
64+
4965
### Values
5066

67+
5168
runKleisli :: forall m a b. Kleisli m a b -> a -> m b

src/Control/Arrow.purs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
module Control.Arrow where
22

3+
import Data.Profunctor.Strong
34
import Data.Tuple (Tuple(..), swap)
45

5-
class (Category a) <= Arrow a where
6+
class (Category a, Strong a) <= Arrow a where
67
arr :: forall b c. (b -> c) -> a b c
7-
first :: forall b c d. a b c -> a (Tuple b d) (Tuple c d)
88

99
instance arrowFunction :: Arrow (->) where
1010
arr f = f
11-
first f (Tuple b d) = Tuple (f b) d
12-
13-
second :: forall a b c d. (Arrow a) => a b c -> a (Tuple d b) (Tuple d c)
14-
second f = arr swap >>> first f >>> arr swap
1511

1612
infixr 3 ***
1713
infixr 3 &&&

src/Control/Arrow/Kleisli.purs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module Control.Arrow.Kleisli where
22

33
import Control.Arrow
4+
import Data.Profunctor
5+
import Data.Profunctor.Strong
46
import Data.Tuple (Tuple(..), swap)
57

68
newtype Kleisli m a b = Kleisli (a -> m b)
@@ -14,6 +16,12 @@ instance semigroupoidKleisli :: (Monad m) => Semigroupoid (Kleisli m) where
1416
instance categoryKleisli :: (Monad m) => Category (Kleisli m) where
1517
id = Kleisli return
1618

19+
instance profunctorKleisli :: (Functor f) => Profunctor (Kleisli f) where
20+
dimap f g (Kleisli h) = Kleisli ((<$>) g <<< h <<< f)
21+
22+
instance strongKleisli :: (Monad m) => Strong (Kleisli m) where
23+
first (Kleisli f) = Kleisli \(Tuple a c) -> f a >>= \b -> return (Tuple b c)
24+
second (Kleisli f) = Kleisli \(Tuple c a) -> f a >>= \b -> return (Tuple c b)
25+
1726
instance arrowKleisli :: (Monad m) => Arrow (Kleisli m) where
1827
arr f = Kleisli (return <<< f)
19-
first (Kleisli f) = Kleisli \(Tuple b d) -> f b >>= \c -> return (Tuple c d)

0 commit comments

Comments
 (0)