Events can carry values. When a signal is declared, the programmer can specify how to combine multiple values emitted at the same instant (the default behavior is to collect all the values into a list).
Here, we define a signal s
which sums the values it receives
during an instant.
signal s default 0 gather (+);;
To get the value of a signal, we can use the construct await s(x)
in e
which waits for the emission of s
and then executes
e
with x
taking the value carried by the signal
s
.
let process print_s = loop await s(x) in print_int x; print_newline () end ;;
#run print_s;;
emit s 1;;
emit s 2;;
emit s 3; emit s 4;;
It is possible to access the last value of a signal using
the last
operator.
last ?s;;