File tree 3 files changed +21
-3
lines changed
3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change
1
+ From ExtLib Require Import
2
+ Monad
3
+ OptionMonad
4
+ StateMonad.
5
+
6
+ (** [Monad_stateT] is not in context, so this definition fails *)
7
+ Fail Definition foo : stateT unit option unit :=
8
+ ret tt.
9
+
10
+ (** Use [Existing Instance] to bring the Local [Monad_stateT] instance into context *)
11
+ Existing Instance Monad_stateT.
12
+
13
+ (** Now the definition succeeds *)
14
+ Definition foo : stateT unit option unit :=
15
+ ret tt.
Original file line number Diff line number Diff line change @@ -7,4 +7,5 @@ MonadReasoning.v
7
7
Printing.v
8
8
UsingSets.v
9
9
WithDemo.v
10
- Notations.v
10
+ Notations.v
11
+ StateTMonad.v
Original file line number Diff line number Diff line change @@ -43,8 +43,10 @@ Section StateType.
43
43
Definition execStateT {t} (c : stateT t) (s : S) : m S :=
44
44
bind (runStateT c s) (fun x => ret (snd x)).
45
45
46
-
47
- Global Instance Monad_stateT : Monad stateT :=
46
+ (** [Monad_stateT] is not a Global Instance because it can cause an infinite loop
47
+ in typeclass inference under certain circumstances. Use [Existing Instance
48
+ Monad_stateT.] to bring the instance into context. *)
49
+ Instance Monad_stateT : Monad stateT :=
48
50
{ ret := fun _ x => mkStateT (fun s => @ret _ M _ (x,s))
49
51
; bind := fun _ _ c1 c2 =>
50
52
mkStateT (fun s =>
You can’t perform that action at this time.
0 commit comments