Skip to content

Commit 06e5989

Browse files
committed
Update introduction
1 parent 7790920 commit 06e5989

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

examples/IntroductionSolutions.v

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ From Coq Require Import
2121
From ExtLib Require Import
2222
Monad
2323
Traversable
24-
Data.List.
24+
Data.List
25+
Data.Monads.StateMonad.
2526

2627
From ITree Require Import
2728
Simple.
@@ -30,6 +31,8 @@ Import ListNotations.
3031
Import ITreeNotations.
3132
Import MonadNotation.
3233
Open Scope monad_scope.
34+
35+
Existing Instance Monad_stateT.
3336
(* end hide *)
3437

3538
(** * Events *)
@@ -75,25 +78,25 @@ Definition write_one : itree ioE unit :=
7578
- [void1] is the empty event (so the resulting ITree can trigger
7679
no event). *)
7780

78-
Compute Monads.stateT (list nat) (itree void1) unit.
81+
Compute stateT (list nat) (itree void1) unit.
7982
Print void1.
8083

8184
Definition handle_io
82-
: forall R, ioE R -> Monads.stateT (list nat) (itree void1) R
83-
:= fun R e log =>
84-
match e with
85-
| Input => ret (log, [0])
86-
| Output o => ret (log ++ o, tt)
87-
end.
85+
: forall R, ioE R -> stateT (list nat) (itree void1) R
86+
:= fun R e => mkStateT (fun log =>
87+
match e in ioE R return itree void1 (R * list nat) with
88+
| Input => ret ([0], log)
89+
| Output o => ret (tt, log ++ o)
90+
end).
8891

8992
(** [interp] lifts any handler into an _interpreter_, of type
9093
[forall R, itree ioE R -> M R]. *)
9194
Definition interp_io
92-
: forall R, itree ioE R -> itree void1 (list nat * R)
93-
:= fun R t => Monads.run_stateT (interp handle_io t) [].
95+
: forall R, itree ioE R -> itree void1 (R * list nat)
96+
:= fun R t => runStateT (interp handle_io t) [].
9497

9598
(** We can now interpret [write_one]. *)
96-
Definition interpreted_write_one : itree void1 (list nat * unit)
99+
Definition interpreted_write_one : itree void1 (unit * list nat)
97100
:= interp_io _ write_one.
98101

99102
(** Intuitively, [interp_io] replaces every [ITree.trigger] in the

0 commit comments

Comments
 (0)