updated csm

This commit is contained in:
Simon Cruanes 2013-09-01 21:37:31 +02:00
parent 53b08fa542
commit bca08783e1
2 changed files with 3 additions and 13 deletions

4
CSM.ml
View file

@ -37,8 +37,6 @@ type 'state t = {
and 'a sm = 'a t and 'a sm = 'a t
and 'event sink = 'event -> unit
and 'a transition = and 'a transition =
| TransitionTo of 'a | TransitionTo of 'a
| TransitionStay | TransitionStay
@ -166,7 +164,7 @@ let filter st p =
Weak.set a 0 (Some st'); Weak.set a 0 (Some st');
register_while st register_while st
(fun _ new_state -> (fun _ new_state ->
if p if p new_state
then begin match Weak.get a 0 with then begin match Weak.get a 0 with
| None -> false | None -> false
| Some st' -> | Some st' ->

12
CSM.mli
View file

@ -36,9 +36,6 @@ type 'state t
(** State machine, whose states are of the type 'state, (** State machine, whose states are of the type 'state,
and that changes state upon events of the type 'event. *) and that changes state upon events of the type 'event. *)
type 'event sink
(** Something that reacts to events of type 'events *)
type 'a transition = type 'a transition =
| TransitionTo of 'a | TransitionTo of 'a
| TransitionStay | TransitionStay
@ -48,7 +45,7 @@ type 'a transition =
val create : ?root:bool -> val create : ?root:bool ->
init:'state -> init:'state ->
trans:('state -> 'event -> 'state transition) -> trans:('state -> 'event -> 'state transition) ->
'state t * 'event sink 'state t * ('event -> unit)
(** Creation of a state machine with an initial state and a (** Creation of a state machine with an initial state and a
given transition function. [root] specifies whether the FSM should given transition function. [root] specifies whether the FSM should
be a GC root and stay alive (default false). be a GC root and stay alive (default false).
@ -77,15 +74,10 @@ val register_while : 'state t -> ('state -> 'state -> bool) -> unit
val register : 'state t -> ('state -> 'state -> unit) -> unit val register : 'state t -> ('state -> 'state -> unit) -> unit
(** Register the given callback forever. *) (** Register the given callback forever. *)
val connect : 'a t -> 'a sink -> unit val connect : 'a t -> ('a -> unit) -> unit
(** [connect st sink] connects state changes of [st] to the sink. The (** [connect st sink] connects state changes of [st] to the sink. The
sink is given only the new state of [st]. *) sink is given only the new state of [st]. *)
val send : 'event sink -> 'event -> unit
(** Trigger an event. This function will not return until no transitions
remain for processing, which means it can take an arbitrary amount of time to
run. *)
(** {2 Combinators} *) (** {2 Combinators} *)
val map : 'a t -> ('a -> 'b) -> 'b t val map : 'a t -> ('a -> 'b) -> 'b t