JoCaml


JoCaml is an experimental functional programming language derived from OCaml. It integrates the primitives of the join-calculus to enable flexible, type-checked concurrent and distributed programming. The current version of JoCaml is a re-implementation of the now unmaintained JoCaml made by Fabrice Le Fessant, featuring a modified syntax and improved OCaml compatibility compared to the original.
JoCaml was used by team Camls 'R Us to implement a distributed ray tracer, earning 2nd place on the ICFP 2000 programming contest.
The name is a reference to Joe Camel, a cartoon camel used in advertisements for Camel-brand cigarettes.

Example


type coins = Nickel | Dime
and drinks = Coffee | Tea
and buttons = BCoffee | BTea | BCancel;;
* '&' in the right hand side is parallel processing
* synchronous_reply : "reply" "to" channel_name
* synchronous channels have function-like types
* while asynchronous ones have type `a Join.chan
* only the last statement in a pattern rhs expression can be an asynchronous message
* 0 in an asynchronous message position means STOP.
*)
def put = print_endline s ; 0
;;
def give = match d with
Coffee -> put
| Tea -> put
;;
def refund = let s = Printf.sprintf "Refund %d" v in put
;;
let new_vending give refund =
let vend = if credit >= cost
then
else
in
def coin & value = value & reply to coin
or coin & value = value & reply to coin
or button & value =
let should_give, remainder = vend 10 v in
else 0 )
& value & reply to button
or button & value =
let should_give, remainder = vend 5 v in
else 0 )
& value & reply to button
or button & value = refund & value & reply to button
in spawn value ;
coin, button
;; *
let ccoin, cbutton = new_vending give refund in
ccoin; ccoin; ccoin;
Unix.sleep; cbutton;
Unix.sleep; cbutton;
Unix.sleep; cbutton;
Unix.sleep
;;

execution

$ jocamlc example.ml -o test
$./test
Coffee
Tea
Refund 5