An Ocaml implementation of Transparent Synchronous Dataflow
- Ocaml 4.05.0 +
oasis2opam
package- In order to run the benchmarks for ReactiveML and JaneStreet Incremental Library, please make sure the following are installed.
- ReactiveML: http://rml.lri.fr/
- Inc:
incremental
package in opam - Zelus: http://zelus.di.ens.fr/
- To pin and install the TSD package, run
make install
and follows the instruction. - To uninstall, run
make uninstall
Run ocamlfind ocamlc -package tsd,tsd.ppx -o $TARGET -linkpkg $SOURCE
to compile your favourite programs.
- To build all the examples, simply run
make examples
. The compiled executable can be found in examples/build/$TARGET/$TARGET. - To execute the benchmarks, simply run
make benchmarks
.
- Run
#ppx "tsd_ext";;
- Run
#require "tsd";;
- Run
open Tsd;;
- Try running
let x = [%dfg 1];;
and it should work!
An extensive description of the language and the underlying calculus can be found in the report Transparent Synchronous Dataflow. Here is a quick recap:
val peek : 'a graph -> 'a
: takes a node in a graph, evaluates it, and returns its valueval root : 'a graph -> 'a graph
: returns the dependencies of a cell (if it is not a cell it gives a runtime error)val cell : 'a graph -> 'a graph
: takes a node in a graph as argument and returns a new cell dependent on the nodeval link : 'a graph -> 'a graph -> unit
: takes a cell and a node and makes the node the (new) dependency of the cell (if the first argument is not a cell it gives a runtime error)val (<~) : 'a graph -> 'a graph -> unit
: alias forlink
val assign : 'a graph -> 'a -> unit
: change the value of a cell (runtime error if argument not a cell)val (<:=) : 'a graph -> 'a -> unit
: alias forassign
val set : 'a graph -> 'a -> unit
: combination oflink
andassign
val (<:~) : 'a graph -> 'a -> unit
: alias forset
val init : unit -> unit
: deletes the dataflow graphval step : unit -> bool
: propagates changes until every cell is changed at most once. It returnstrue
if changes were made.
The tag [%dfg t]
always returns a node in a graph that corresponds to t
. Note that this node is not a cell. For example
let x = [%dfg 1]
creates a constant graph with node 1
. This let f = [%dfg fun x y -> x * y]
creates a function from graphs to graphs which can be used as follows:
let ( * ) = lift ( * );;
let f = [%dfg fun x y -> x * y];;
let x = cell [%dfg 1] ;;
let y = cell [%dfg 2] ;;
let m = [%dfg f x y];;
This creates a dataflow graph with two cells, initialised to 1 and 2, connected via multiplication to the node x
(which is not a cell).