Support.State
State monad definition.
The state monad is used to define stateful actions, i.e. actions that can read or write to some auxiliary data structure. In general, using the state monad is slower than using side effects because of extra memory allocations and eager closure constructions. For helpers to operations defined with respect to mutable states, see Imperative_state
.
In order to effectively use the state monad, you should define:
For instance:
module type DISAMBIGUATION_STATE = sig
include State.STATE
val with_bound_lf_variable : Identifier.t -> 'a t -> 'a t
(* ... *)
end
module Immutable_disambiguation_state : sig
include DISAMBIGUATION_STATE
val initial_state : state
end = struct
(* ... *)
end
module Mutable_disambiguation_state : sig
include DISAMBIGUATION_STATE
val create_initial_state : unit -> state
end = struct
(* ... *)
end
module type LF_DISAMBIGUATION = sig
include State.STATE
val disambiguate_lf_kind : Synprs.lf_object -> Synext.lf_kind t
(* ... *)
end
module Make_lf_disambiguation
(Disambiguation_state : DISAMBIGUATION_STATE) :
LF_DISAMBIGUATION with type state = Disambiguation_state.state =
struct
(* ... *)
end