Skip to content

Commit 273453a

Browse files
committed
refactor: redo signatures and fix documentation
1 parent 80dca8d commit 273453a

File tree

11 files changed

+54
-63
lines changed

11 files changed

+54
-63
lines changed

src/Reader.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
module type S =
22
sig
3-
module Env : Sigs.Type
4-
5-
val read : unit -> Env.t
6-
val scope : (Env.t -> Env.t) -> (unit -> 'a) -> 'a
7-
val run : env:Env.t -> (unit -> 'a) -> 'a
3+
type env
4+
val read : unit -> env
5+
val scope : (env -> env) -> (unit -> 'a) -> 'a
6+
val run : env:env -> (unit -> 'a) -> 'a
87
val register_printer : ([`Read] -> string option) -> unit
98
end
109

src/Reader.mli

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,21 @@
1616
]}
1717
*)
1818

19-
(** This should be equivalent to {!Unmonad} applying to the standard reader monad. *)
20-
2119
module type S =
2220
sig
2321
(** Signatures of read effects. *)
2422

25-
(** Type of environments. *)
26-
module Env : Sigs.Type
27-
(** @open *)
23+
type env
24+
(** The type of environments. *)
2825

29-
val read : unit -> Env.t
26+
val read : unit -> env
3027
(** Read the environment. *)
3128

32-
val scope : (Env.t -> Env.t) -> (unit -> 'a) -> 'a
29+
val scope : (env -> env) -> (unit -> 'a) -> 'a
3330
(** [scope f t] runs the thunk [t] under the new environment that is the result of applying [f] to the current environment. *)
3431

35-
val run : env:Env.t -> (unit -> 'a) -> 'a
36-
(** [run t] runs the thunk [t] which may perform reading effects. *)
32+
val run : env:env -> (unit -> 'a) -> 'a
33+
(** [run ~env t] runs the thunk [t] which may perform reading effects on the value [env]. *)
3734

3835
val register_printer : ([`Read] -> string option) -> unit
3936
(** [register_printer p] registers a printer [p] via {!val:Printexc.register_printer} to convert the unhandled internal effect into a string for the OCaml runtime system to display. Ideally, the internal effect should have been handled by {!val:run} and there is no need to use this function, but when it is not the case, this function can be helpful for debugging. The functor {!module:Reader.Make} always registers a simple printer to suggest using {!val:run}, but you can register new ones to override it. The return type of the printer [p] should return [Some s] where [s] is the resulting string, or [None] if it chooses not to convert a particular effect. The registered printers are tried in reverse order until one of them returns [Some s] for some [s]; that is, the last registered printer is tried first. Note that this function is a wrapper of {!val:Printexc.register_printer} and all the registered printers (via this function or {!val:Printexc.register_printer}) are put into the same list.
@@ -44,5 +41,5 @@ sig
4441
*)
4542
end
4643

47-
module Make (Env : Sigs.Type) : S with module Env := Env
44+
module Make (Env : Sigs.Type) : S with type env := Env.t
4845
(** The implementation of read effects. *)

src/Sequencer.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
module type S =
22
sig
3-
module Elt : Sigs.Type
4-
5-
val yield : Elt.t -> unit
6-
val run : (unit -> unit) -> Elt.t Seq.t
7-
val register_printer : ([`Yield of Elt.t] -> string option) -> unit
3+
type elt
4+
val yield : elt -> unit
5+
val run : (unit -> unit) -> elt Seq.t
6+
val register_printer : ([`Yield of elt] -> string option) -> unit
87
end
98

109
module Make (Elt : Sigs.Type) =

src/Sequencer.mli

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ module type S =
1919
sig
2020
(** Signatures of sequencing effects. *)
2121

22-
module Elt : Sigs.Type
23-
(** @open *)
22+
type elt
23+
(** The type of elements. *)
2424

25-
val yield : Elt.t -> unit
25+
val yield : elt -> unit
2626
(** Yield the element. *)
2727

28-
val run : (unit -> unit) -> Elt.t Seq.t
28+
val run : (unit -> unit) -> elt Seq.t
2929
(** [run t] runs the thunk [t] which may perform sequencing effects. *)
3030

31-
val register_printer : ([`Yield of Elt.t] -> string option) -> unit
31+
val register_printer : ([`Yield of elt] -> string option) -> unit
3232
(** [register_printer p] registers a printer [p] via {!val:Printexc.register_printer} to convert unhandled internal effects into strings for the OCaml runtime system to display. Ideally, all internal effects should have been handled by {!val:run} and there is no need to use this function, but when it is not the case, this function can be helpful for debugging. The functor {!module:Sequencer.Make} always registers a simple printer to suggest using {!val:run}, but you can register new ones to override it. The return type of the printer [p] should return [Some s] where [s] is the resulting string, or [None] if it chooses not to convert a particular effect. The registered printers are tried in reverse order until one of them returns [Some s] for some [s]; that is, the last registered printer is tried first. Note that this function is a wrapper of {!val:Printexc.register_printer} and all the registered printers (via this function or {!val:Printexc.register_printer}) are put into the same list.
3333
3434
The input type of the printer [p] is a variant representation of the internal effects used in this module. They correspond to the effects trigger by {!val:yield}. More precisely, [`Yield elt] corresponds to the effect triggered by [yield elt].
@@ -37,5 +37,5 @@ sig
3737
*)
3838
end
3939

40-
module Make (Elt : Sigs.Type) : S with module Elt := Elt
40+
module Make (Elt : Sigs.Type) : S with type elt := Elt.t
4141
(** The implementation of sequencing effects. *)

src/State.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
module type S =
22
sig
3-
module State : Sigs.Type
4-
5-
val get : unit -> State.t
6-
val set : State.t -> unit
7-
val modify : (State.t -> State.t) -> unit
8-
val run : init:State.t -> (unit -> 'a) -> 'a
9-
val register_printer : ([`Get | `Set of State.t] -> string option) -> unit
3+
type state
4+
val get : unit -> state
5+
val set : state -> unit
6+
val modify : (state -> state) -> unit
7+
val run : init:state -> (unit -> 'a) -> 'a
8+
val register_printer : ([`Get | `Set of state] -> string option) -> unit
109
end
1110

1211
module Make (State : Sigs.Type) =

src/State.mli

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,27 @@
1111
]}
1212
*)
1313

14-
(** This should be equivalent to {!module:Unmonad} applying to the standard state monad when continuations are one-shot.
15-
(The current implementation uses mutable references and this statement has not been formally proved.) *)
16-
1714
module type S =
1815
sig
1916
(** Signatures of read effects. *)
2017

21-
module State : Sigs.Type
22-
(** @open *)
18+
type state
19+
(** The type of states. *)
2320

24-
val get : unit -> State.t
21+
val get : unit -> state
2522
(** [get ()] reads the current state. *)
2623

27-
val set : State.t -> unit
24+
val set : state -> unit
2825
(** [set x] makes [x] the new state. *)
2926

30-
val modify : (State.t -> State.t) -> unit
27+
val modify : (state -> state) -> unit
3128
(** [modify f] applies [f] to the current state and then set the result as the new state. *)
3229

33-
val run : init:State.t -> (unit -> 'a) -> 'a
34-
(** [run t] runs the thunk [t] which may perform state effects. *)
30+
val run : init:state -> (unit -> 'a) -> 'a
31+
(** [run ~init t] runs the thunk [t] which may perform state effects. The initial state is [init]. *)
3532

36-
val register_printer : ([`Get | `Set of State.t] -> string option) -> unit
37-
(** [register_printer p] registers a printer [p] via {!val:Printexc.register_printer} to convert unhandled internal effects into strings for the OCaml runtime system to display. Ideally, all internal effects should have been handled by {!val:run} and there is no need to use this function, but when it is not the case, this function can be helpful for debugging. The functor {!module:State.Make} always registers a simple printer to suggest using {!val:run}, but you can register new ones to override it. The return type of the printer [p] should return [Some s] where [s] is the resulting string, or [None] if it chooses not to convert a particular effect. The registered printers are tried in reverse order until one of them returns [Some s] for some [s]; that is, the last registered printer is tried first. Note that this function is a wrapper of {!val:Printexc.register_printer} and all the registered printers (via this function or {!val:Printexc.register_printer}) are put into the same list.
33+
val register_printer : ([`Get | `Set of state] -> string option) -> unit
34+
(** [register_printer p] registers a printer [p] via {!val:Printexc.register_printer} to convert unhandled internal effects into strings for the OCaml runtime system to display. Ideally, all internal effects should have been handled by {!val:run} and there is no need to use this function, but when it is not the case, this function can be helpful for debugging. The functor {!module:Make} always registers a simple printer to suggest using {!val:run}, but you can register new ones to override it. The return type of the printer [p] should return [Some s] where [s] is the resulting string, or [None] if it chooses not to convert a particular effect. The registered printers are tried in reverse order until one of them returns [Some s] for some [s]; that is, the last registered printer is tried first. Note that this function is a wrapper of {!val:Printexc.register_printer} and all the registered printers (via this function or {!val:Printexc.register_printer}) are put into the same list.
3835
3936
The input type of the printer [p] is a variant representation of the internal effects used in this module. They correspond to the effects trigger by {!val:get} and {!val:set}. More precisely,
4037
- [`Get] corresponds to the effect triggered by [get ()].
@@ -44,5 +41,5 @@ sig
4441
*)
4542
end
4643

47-
module Make (State : Sigs.Type) : S with module State := State
44+
module Make (State : Sigs.Type) : S with type state := State.t
4845
(** The implementation of state effects. *)

src/UniqueID.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module type S =
22
sig
3-
module Elt : Sigs.Type
3+
type elt
44

55
module ID :
66
sig
@@ -12,11 +12,11 @@ sig
1212
end
1313
type id = ID.t
1414

15-
val register : Elt.t -> id
16-
val retrieve : id -> Elt.t
17-
val export : unit -> Elt.t Seq.t
18-
val run : ?init:Elt.t Seq.t -> (unit -> 'a) -> 'a
19-
val register_printer : ([`Register of Elt.t | `Retrieve of id | `Export] -> string option) -> unit
15+
val register : elt -> id
16+
val retrieve : id -> elt
17+
val export : unit -> elt Seq.t
18+
val run : ?init:elt Seq.t -> (unit -> 'a) -> 'a
19+
val register_printer : ([`Register of elt | `Retrieve of id | `Export] -> string option) -> unit
2020
end
2121

2222
module Make (Elt : Sigs.Type) =

src/UniqueID.mli

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module type S =
77
sig
88
(** Signatures of the effects. *)
99

10-
module Elt : Sigs.Type
11-
(** @open *)
10+
type elt
11+
(** The type of elements *)
1212

1313
(** The type of IDs and its friends. *)
1414
module ID :
@@ -32,22 +32,22 @@ sig
3232
type id = ID.t
3333
(** The type of unique IDs. The client should not assume a particular indexing scheme. *)
3434

35-
val register : Elt.t -> id
35+
val register : elt -> id
3636
(** Register a new item and get an ID. Note that registering the same item twice will get two different IDs. *)
3737

38-
val retrieve : id -> Elt.t
38+
val retrieve : id -> elt
3939
(** Retrieve the item associated with the ID. *)
4040

41-
val export : unit -> Elt.t Seq.t
41+
val export : unit -> elt Seq.t
4242
(** Export the internal storage for serialization. Once exported, the representation is persistent and can be traversed without the effect handler. *)
4343

44-
val run : ?init:Elt.t Seq.t -> (unit -> 'a) -> 'a
44+
val run : ?init:elt Seq.t -> (unit -> 'a) -> 'a
4545
(** [run t] runs the thunk [t] and handles the effects for generating unique IDs.
4646
4747
@param init The initial storage, which should be the output of some previous {!val:export}.
4848
*)
4949

50-
val register_printer : ([`Register of Elt.t | `Retrieve of id | `Export] -> string option) -> unit
50+
val register_printer : ([`Register of elt | `Retrieve of id | `Export] -> string option) -> unit
5151
(** [register_printer p] registers a printer [p] via {!val:Printexc.register_printer} to convert unhandled internal effects into strings for the OCaml runtime system to display. Ideally, all internal effects should have been handled by {!val:run} and there is no need to use this function, but when it is not the case, this function can be helpful for debugging. The functor {!module:UniqueID.Make} always registers a simple printer to suggest using {!val:run}, but you can register new ones to override it. The return type of the printer [p] should return [Some s] where [s] is the resulting string, or [None] if it chooses not to convert a particular effect. The registered printers are tried in reverse order until one of them returns [Some s] for some [s]; that is, the last registered printer is tried first. Note that this function is a wrapper of {!val:Printexc.register_printer} and all the registered printers (via this function or {!val:Printexc.register_printer}) are put into the same list.
5252
5353
The input type of the printer [p] is a variant representation of the internal effects used in this module. They correspond to the effects trigger by {!val:register}, {!val:retrieve} and {!val:export}. More precisely,
@@ -59,5 +59,5 @@ sig
5959
*)
6060
end
6161

62-
module Make (Elt : Sigs.Type) : S with module Elt := Elt
62+
module Make (Elt : Sigs.Type) : S with type elt := Elt.t
6363
(** The implementation of the effects. *)

test/TestReader.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let gen_cmd =
3838

3939
let gen_prog = Q.Gen.list gen_cmd
4040

41-
module ReaderTester (S : Algaeff.Reader.S with module Env := Int) =
41+
module ReaderTester (S : Algaeff.Reader.S with type env := int) =
4242
struct
4343
let trace ~env prog =
4444
let rec go =

test/TestSequencer.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ and prog = cmd list
3434
let gen_cmd = Q.Gen.map (fun i -> Yield i) Q.Gen.int
3535
let gen_prog = Q.Gen.list gen_cmd
3636

37-
module SequencerTester (S : Algaeff.Sequencer.S with module Elt := Int) =
37+
module SequencerTester (S : Algaeff.Sequencer.S with type elt := int) =
3838
struct
3939
let trace (prog : prog) =
4040
let go = function (Yield i) -> S.yield i in

0 commit comments

Comments
 (0)