Skip to content

Commit 174889d

Browse files
authored
Merge pull request #44 from vzaliva/mcompose
added monadic composition operator `>=>`
2 parents 548c861 + b480c83 commit 174889d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

theories/Structures/Monad.v

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ Section monadic.
5252
{M : Monad m}
5353
{A B : Type@{d}} (fM:m (A -> B)) (aM:m A) : m B :=
5454
bind fM (fun f => liftM f aM).
55+
56+
(* Left-to-right composition of Kleisli arrows. *)
57+
Definition mcompose@{c d}
58+
{m:Type@{d}->Type@{c}}
59+
{M: Monad m}
60+
{T U V:Type@{d}}
61+
(f: T -> m U) (g: U -> m V): (T -> m V) :=
62+
fun x => bind (f x) g.
63+
5564
End monadic.
5665

5766
Module MonadNotation.
@@ -60,6 +69,7 @@ Module MonadNotation.
6069

6170
Notation "c >>= f" := (@pbind _ _ _ _ _ c f) (at level 50, left associativity) : monad_scope.
6271
Notation "f =<< c" := (@pbind _ _ _ _ _ c f) (at level 51, right associativity) : monad_scope.
72+
Notation "f >=> g" := (@mcompose _ _ _ _ _ f g) (at level 50, left associativity) : monad_scope.
6373

6474
Notation "x <- c1 ;; c2" := (@pbind _ _ _ _ _ c1 (fun x => c2))
6575
(at level 100, c1 at next level, right associativity) : monad_scope.

0 commit comments

Comments
 (0)