Let's now see how we can change the behavior of a process. We define a
process replace
which takes as argument an initial
behavior p_init
, a state state
and a
signal new_behavior
on which new behavior to replace the
current behavior can be sent.
let rec process replace p_init state new_behavior = do run (p_init state) until new_behavior(p) -> run (replace p state new_behavior) done
The process p_init
parameterized by state
is
executed under the control of the
signal new_behavior
. When new_behavior
is
emitted, p_init
is stopped and we receive the process
p
carried on this signal. The new process p
is executed through the recursive call to replace
, which
continues to allow changes to the behavior of the process.