OCaml code

ReactiveML is an extension of OCaml. Therefore, OCaml phrases are also ReactiveML phrases. For example, we can evaluate an expression (you can simply click on the code to load it in the terminal):

1 + 2 ;;

define a global value (note that the type infered by the compiler is printed first by the ReactiveML compiler and then by the OCaml compiler):

let a = 1 ;;

define a type:

type 'a tree =
  | Leaf of 'a
  | Node of 'a * 'a tree * 'a tree ;;

define a recursive function and apply it:

let rec depth t =
  match t with
  | Leaf _ -> 1
  | Node (_, t1, t2) -> 1 + max (depth t1) (depth t2) ;;

depth (Node (1, Node (2, Leaf 4, Leaf 5), Leaf 3)) ;;

Functions of the OCaml standard library are also available.

List.rev [ "a" ; "b" ; "c" ] ;;