Skip to content

Commit f2b709f

Browse files
Lysxialiyishuai
authored andcommitted
Re-add continuation monad
1 parent a1b6f91 commit f2b709f

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

theories/Data/Monads/ContMonad.v

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Require Import ExtLib.Structures.Monad.
2+
Require Import ExtLib.Structures.MonadTrans.
23

34
Set Implicit Arguments.
4-
Set Strict Implicit.
5+
Set Contextual Implicit.
6+
Set Maximal Implicit Insertion.
57

6-
(*
78
Section ContType.
8-
Variable Ans : Type.
9-
9+
Variable R : Type.
1010

1111
(*
1212
Record cont (t : Type) : Type := mkCont
@@ -31,23 +31,19 @@ Section ContType.
3131
mkCont (fun x => runCont c (f x)).
3232
*)
3333

34-
Variable m : Type -> Type.
34+
Variable M : Type -> Type.
3535

36-
Record contT (t : Type) : Type := mkContT
37-
{ runContT : (t -> m Ans) -> m Ans }.
36+
Record contT (A : Type) : Type := mkContT
37+
{ runContT : (A -> M R) -> M R }.
3838

3939
Global Instance Monad_contT : Monad contT :=
4040
{ ret := fun _ x => mkContT (fun k => k x)
41-
; bind := fun _ c1 _ c2 =>
41+
; bind := fun _ _ c1 c2 =>
4242
mkContT (fun c =>
4343
runContT c1 (fun a => runContT (c2 a) c))
4444
}.
4545

46-
Global Instance Cont_contT : Cont contT :=
47-
{ callCC := fun _ _ f => mkContT (fun c => runContT (f (fun x => mkContT (fun _ => c x))) c)
48-
}.
49-
50-
Global Instance MonadT_contT (M : Monad m) : MonadT contT m :=
46+
Global Instance MonadT_contT {Monad_M : Monad M} : MonadT contT M :=
5147
{ lift := fun _ c => mkContT (bind c)
5248
}.
5349

@@ -60,4 +56,10 @@ Section ContType.
6056
*)
6157

6258
End ContType.
63-
*)
59+
60+
Definition resetT {M} {Monad_M : Monad M} {R R'} (u : contT R M R) : contT R' M R :=
61+
mkContT (fun k => bind (runContT u ret) k).
62+
63+
Definition shiftT {M} {Monad_M : Monad M} {R A}
64+
(f : (A -> M R) -> contT R M R) : contT R M A :=
65+
mkContT (fun k => runContT (f k) ret).

0 commit comments

Comments
 (0)