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

Commit b05cb84

Browse files
committed
Add Kleisli arrows
1 parent 4f1021c commit b05cb84

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Control/Arrow/Kleisli.purs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Control.Arrow.Kleisli where
2+
3+
import Control.Arrow
4+
import Data.Tuple (Tuple(..), swap)
5+
6+
data Kleisli m a b = Kleisli (a -> m b)
7+
8+
runKleisli :: forall m a b. Kleisli m a b -> a -> m b
9+
runKleisli (Kleisli f) = f
10+
11+
instance categoryKleisli :: (Monad m) => Category (Kleisli m) where
12+
id = Kleisli return
13+
(<<<) (Kleisli f) (Kleisli g) = Kleisli (\b -> g b >>= f)
14+
15+
instance arrowKleisli :: (Monad m) => Arrow (Kleisli m) where
16+
arr f = Kleisli (return <<< f)
17+
first (Kleisli f) = Kleisli \(Tuple b d) -> f b >>= \c -> return (Tuple c d)

0 commit comments

Comments
 (0)