Hi everyone,
I also made this package a bit ago (didn’t know about discuss.ocaml.org until yesterday) called forcamla (opam). You can think of it like a very powerful spreadsheet editor. In particular, in forcamla we equate variables instead of assign them. forcamla also combines the power of spreadsheets with event listeners to organize program execution.
A Small Example
open Formula (* To use formula *)
let x = v 2 (* Create an integer term called x *)
let y = v 2 (* Create an integer term called y *)
let z = x + y
let () = x =: 3 (* Set x to 3, and z now is 5 *)
Observe there is no need to reassign z. It was equated to x + y and will always update whenever x or y change.
Event Listeners
You can also construct event listeners using this framework. Here is a small game example to illustrate this:
open Formula
type hero =
{
(* A bunuch of fields *)
health: int formula
}
let player =
{
(* Assign the fields *)
health = v 3; (* Give health a value of something, say 3 in this case. *)
}
let game_over () = print_endline "Game Over!"
let () = when_satisfied (player.health =? 0) game_over
Then you can do this:
let () = player.health =: !(player.health - c 1) (* Nothing happens yet! player.health is 2 now. *)
let () = player.health =: !(player.health - c 1) (* Nothing happens yet! player health is 1 now. *)
let () = player.health =: !(player.health - c 1) (* Now something happens! player.health is 0 and "Game Over!" is printed to the screen! *)
Why?
I originally designed forcamla for games but I realized it is just a useful organizational tool in general. It is similar to Jane Street’s Incremental but forcamla prioritizes ergonomics over efficiency.