JoCaml
JoCaml[1][2] is an experimental general-purpose, high-level, multi-paradigm, functional and object-oriented 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[3] 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,[4] 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. Exampletype coins = Nickel | Dime
and drinks = Coffee | Tea
and buttons = BCoffee | BTea | BCancel;;
(* def defines a Join-pattern alternatives set clause
* '&' in the left side of '=' means join (channel synchronism)
* '&' in the right hand side is parallel processing
* synchronous_reply :== "reply" [x] "to" channel_name
* synchronous channels have function-like types (`a -> `b)
* 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 ("no sent message" in CSP terminology).
*)
def put(s) = print_endline s ; 0 (* STOP *)
;; (* put: string Join.chan *)
def give(d) = match d with
Coffee -> put("Coffee")
| Tea -> put("Tea")
;; (* give: drink Join.chan *)
def refund(v) = let s = Printf.sprintf "Refund %d" v in put(s)
;; (* refund: int Join.chan *)
let new_vending give refund =
let vend (cost:int) (credit:int) = if credit >= cost
then (true, credit - cost)
else (false, credit)
in
def coin(Nickel) & value(v) = value(v+5) & reply to coin
or coin(Dime) & value(v) = value(v+10) & reply to coin
or button(BCoffee) & value(v) =
let should_give, remainder = vend 10 v in
(if should_give then give(Coffee) else 0 (* STOP *))
& value(remainder) & reply to button
or button(BTea) & value(v) =
let should_give, remainder = vend 5 v in
(if should_give then give(Tea) else 0 (* STOP *))
& value(remainder) & reply to button
or button(BCancel) & value(v) = refund( v) & value(0) & reply to button
in spawn value(0) ;
coin, button (* coin, button: int -> unit *)
;; (* new_vending: drink Join.chan -> int Join.chan -> (int->unit)*(int->unit) *)
let ccoin, cbutton = new_vending give refund in
ccoin(Nickel); ccoin(Nickel); ccoin(Dime);
Unix.sleep(1); cbutton(BCoffee);
Unix.sleep(1); cbutton(BTea);
Unix.sleep(1); cbutton(BCancel);
Unix.sleep(1) (* let the last message show up *)
;;
execution $ jocamlc example.ml -o test
$ ./test
Coffee
Tea
Refund 5
See alsoReferences
External links
Information related to JoCaml |
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve