Skip to content

Commit

Permalink
docs: properly document register_printer
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Sep 23, 2023
1 parent 330d703 commit f3ef7fc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Reader.mli
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ sig
val run : env:env -> (unit -> 'a) -> 'a
(** [run t] runs the thunk [t] which may perform reading effects. *)

(**/**)
val register_printer : ([`Read] -> string option) -> unit
(** [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:Modifier.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.
The input type of the printer [p] is a variant representation of the only internal effect used in this module. It corresponds to the effect trigger by {!val:read}.
@since 1.0.0
*)
end

module Make (P : Param) : S with type env = P.env
Expand Down
7 changes: 6 additions & 1 deletion src/Sequencer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ sig
val run : (unit -> unit) -> elt Seq.t
(** [run t] runs the thunk [t] which may perform sequencing effects. *)

(**/**)
val register_printer : ([`Yield of elt] -> string option) -> unit
(** [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:Modifier.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.
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].
@since 1.0.0
*)
end

module Make (P : Param) : S with type elt = P.elt
Expand Down
9 changes: 8 additions & 1 deletion src/State.mli
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ sig
val run : init:state -> (unit -> 'a) -> 'a
(** [run t] runs the thunk [t] which may perform state effects. *)

(**/**)
val register_printer : ([`Get | `Set of state] -> string option) -> unit
(** [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:Modifier.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.
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,
- [`Get] corresponds to the effect triggered by [get ()].
- [`Set state] corresponds to the effect triggered by [set state].
@since 1.0.0
*)
end

module Make (P : Param) : S with type state = P.state
Expand Down
10 changes: 9 additions & 1 deletion src/UniqueID.mli
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ sig
@param init The initial storage, which should be the output of some previous {!val:export}.
*)

(**/**)
val register_printer : ([`Register of elt | `Retrieve of id | `Export] -> string option) -> unit
(** [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:Modifier.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.
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,
- [`Register elt] corresponds to the effect triggered by [register elt].
- [`Retrieve id] corresponds to the effect triggered by [retrieve id].
- [`Export] corresponds to the effect triggered by [export ()].
@since 1.0.0
*)
end

module Make (P : Param) : S with type elt = P.elt
Expand Down

0 comments on commit f3ef7fc

Please sign in to comment.