Skip to content

Commit 04e00a9

Browse files
committed
wip port of to final effect syntax
1 parent 78cf6f6 commit 04e00a9

3 files changed

Lines changed: 15 additions & 18 deletions

File tree

‎fringe.ml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ module SameFringe(E : EQUATABLE) = struct
2525
type nonrec tree = E.t tree
2626

2727
(* Yielding control *)
28-
effect Yield : E.t -> unit
28+
type _ eff += Yield : E.t -> unit eff
29+
2930
let yield e = perform (Yield e)
3031

3132
(* The walk routine *)
@@ -43,7 +44,7 @@ module SameFringe(E : EQUATABLE) = struct
4344
let step f =
4445
match f () with
4546
| _ -> Done
46-
| effect (Yield e) k -> Yielded (e, k)
47+
| effect Yield e, k -> Yielded (e, k)
4748

4849
(* The comparator "step walks" two given trees simultaneously *)
4950
let comparator ltree rtree =

‎ref.ml‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ module FCMBasedHeap : HEAP = functor (Cell : CELL) -> struct
5252
(* [EFF] declares a pair of effect names [Get] and [Set]. *)
5353
module type EFF = sig
5454
type t
55-
effect Get : t
56-
effect Set : t -> unit
55+
type _ eff += Get : t eff | Set : t -> unit eff
5756
end
5857
(* ['a t] is the type of first-class [EFF] modules.
5958
The effect-name declarations in [EFF] become first-class. *)
6059
type 'a t = (module EFF with type t = 'a)
6160

62-
effect Ref : 'a -> 'a t
61+
type _ eff += Ref : 'a -> 'a t unit
6362

6463
let ref init = perform (Ref init)
6564
let (!) : type a. a t -> a =
@@ -72,21 +71,20 @@ module FCMBasedHeap : HEAP = functor (Cell : CELL) -> struct
7271
let fresh (type a) () : a t =
7372
(module struct
7473
type t = a
75-
effect Get : t
76-
effect Set : t -> unit
74+
type _ eff += Get : t eff | Set : t -> unit eff
7775
end)
7876

7977
let run main =
8078
try main () with
81-
effect (Ref init) k ->
79+
effect (Ref init), k ->
8280
(* trick to name the existential type introduced by the matching: *)
8381
(init, k) |> fun (type a) (init, k : a * (a t, _) continuation) ->
8482
let module E = (val (fresh (): a t)) in
8583
let module C = Cell(struct type t = a end) in
8684
let main () =
8785
try continue k (module E) with
88-
| effect E.Get k -> continue k (C.get() : a)
89-
| effect (E.Set y) k -> continue k (C.set y)
86+
| effect E.Get, k -> continue k (C.get() : a)
87+
| effect (E.Set y), k -> continue k (C.set y)
9088
in
9189
snd (C.run ~init main)
9290
end
@@ -108,15 +106,15 @@ module RecordBasedHeap : HEAP = functor (Cell : CELL) -> struct
108106
get : unit -> 'a;
109107
set : 'a -> unit;
110108
}
111-
effect Ref : 'a -> 'a t
109+
type _ eff += Ref : 'a -> 'a t eff
112110

113111
let ref init = perform (Ref init)
114112
let (!) {get; _} = get()
115113
let (:=) {set; _} y = set y
116114

117115
let run main =
118116
try main () with
119-
| effect (Ref init) k ->
117+
| effect (Ref init), k ->
120118
(init, k) |> fun (type a) ((init, k) : a * (a t, _) continuation) ->
121119
let open Cell(struct type t = a end) in
122120
snd (run ~init (fun _ -> continue k {get; set}))

‎state.ml‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ end
138138
*)
139139
module LocalMutVar : CELL = functor (T : TYPE) -> struct
140140
type t = T.t
141-
effect Get : t
142-
effect Set : t -> unit
141+
type _ eff += Get : t eff | Set : t -> unit eff
143142

144143
let get () = perform Get
145144
let set y = perform (Set y)
@@ -148,8 +147,8 @@ module LocalMutVar : CELL = functor (T : TYPE) -> struct
148147
let var = ref init in
149148
match main () with
150149
| res -> !var, res
151-
| effect Get k -> continue k (!var : t)
152-
| effect (Set y) k -> var := y; continue k ()
150+
| effect Get, k -> continue k (!var : t)
151+
| effect (Set y), k -> var := y; continue k ()
153152
end
154153

155154

@@ -180,8 +179,7 @@ end
180179
*)
181180
module StPassing : CELL = functor (T : TYPE) -> struct
182181
type t = T.t
183-
effect Get : t
184-
effect Set : t -> unit
182+
type _ eff += Get : t eff | Set : t -> unit eff
185183

186184
let get () = perform Get
187185
let set y = perform (Set y)

0 commit comments

Comments
 (0)