expose more functions in Automaton

This commit is contained in:
Simon Cruanes 2013-12-30 17:59:39 +01:00
parent 79e40e03a8
commit 53d7c7cfb8
2 changed files with 21 additions and 10 deletions

View file

@ -67,7 +67,9 @@ let product f1 f2 (s1, s2) i =
module I = struct
type 'a t = 'a -> unit
let send x i = i x
let create f = f
let send x i = x i
let comap f i x = i (f x)
@ -153,7 +155,7 @@ module O = struct
end
let connect o i =
O.on o (fun x -> I.send x i; true)
O.on o (fun x -> I.send i x; true)
module Instance = struct
type ('s, 'i, 'o) t = {
@ -174,6 +176,8 @@ module Instance = struct
let transitions a = a.transitions
let send a i = I.send a.i i
let _q = Queue.create ()
let _process q =

View file

@ -61,17 +61,14 @@ Input sink, that accepts values of a given type. Cofunctor. *)
module I : sig
type -'a t
val create : ('a -> unit) -> 'a t
val comap : ('a -> 'b) -> 'b t -> 'a t
val filter : ('a -> bool) -> 'a t -> 'a t
val send : 'a -> 'a t -> unit
(** [send a i] uses [a]'s transition function to update [a] with the input
event [i]. The output of the transition function (a list of outputs) is
recursively processed.
This may not terminate, if the automata keep on creating new outputs that
trigger other outputs forever. *)
val send : 'a t -> 'a -> unit
(** [send a i] inputs [i] on the channel [a]. *)
end
(** {2 Output}
@ -81,6 +78,8 @@ Stream of output values. Functor. *)
module O : sig
type 'a t
val create : unit -> 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
val filter : ('a -> bool) -> 'a t -> 'a t
@ -89,6 +88,8 @@ module O : sig
val once : 'a t -> ('a -> unit) -> unit
val send : 'a t -> 'a -> unit
val propagate : 'a t -> 'a t -> unit
(** [propagate a b] forwards all elements of [a] into [b]. As long as [a]
exists, [b] will not be GC'ed. *)
@ -115,7 +116,13 @@ module Instance : sig
val transitions : ('s, 'i, 'o) t -> ('s * 'i * 's * 'o list) O.t
val send : (_, 'i, _) t -> 'i -> unit
(** Shortcut to send an input *)
val create : f:('s, 'i, 'o) automaton -> 's -> ('s, 'i, 'o) t
(** [create ~f init] creates an instance of [f] with initial state
[init]. *)
[init].
@param f the transition function
@param init the initial state *)
end