|
11 | 11 | ]} |
12 | 12 | *) |
13 | 13 |
|
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 | | - |
17 | 14 | module type S = |
18 | 15 | sig |
19 | 16 | (** Signatures of read effects. *) |
20 | 17 |
|
21 | | - module State : Sigs.Type |
22 | | - (** @open *) |
| 18 | + type state |
| 19 | + (** The type of states. *) |
23 | 20 |
|
24 | | - val get : unit -> State.t |
| 21 | + val get : unit -> state |
25 | 22 | (** [get ()] reads the current state. *) |
26 | 23 |
|
27 | | - val set : State.t -> unit |
| 24 | + val set : state -> unit |
28 | 25 | (** [set x] makes [x] the new state. *) |
29 | 26 |
|
30 | | - val modify : (State.t -> State.t) -> unit |
| 27 | + val modify : (state -> state) -> unit |
31 | 28 | (** [modify f] applies [f] to the current state and then set the result as the new state. *) |
32 | 29 |
|
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]. *) |
35 | 32 |
|
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. |
38 | 35 |
|
39 | 36 | 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, |
40 | 37 | - [`Get] corresponds to the effect triggered by [get ()]. |
|
44 | 41 | *) |
45 | 42 | end |
46 | 43 |
|
47 | | -module Make (State : Sigs.Type) : S with module State := State |
| 44 | +module Make (State : Sigs.Type) : S with type state := State.t |
48 | 45 | (** The implementation of state effects. *) |
0 commit comments