JoCaml is an experimental
general-purpose,
high-level,
multi-paradigm
Programming languages can be grouped by the number and types of Programming paradigm, paradigms supported.
Paradigm summaries
A concise reference for the programming paradigms listed in this article.
* Concurrent programming language, Concurrent ...
,
functional and
object-oriented
Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impleme ...
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
derived from
OCaml
OCaml ( , formerly Objective Caml) is a General-purpose programming language, general-purpose, High-level programming language, high-level, Comparison of multi-paradigm programming languages, multi-paradigm programming language which extends the ...
. 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
Joe Camel (also called Old Joe) was an advertising mascot used by the R. J. Reynolds Tobacco Company (RJR) for their cigarette brand Camel (cigarette), Camel. The character was created in 1974 for a French advertising campaign, and was redesign ...
, a cartoon
camel
A camel (from and () from Ancient Semitic: ''gāmāl'') is an even-toed ungulate in the genus ''Camelus'' that bears distinctive fatty deposits known as "humps" on its back. Camels have long been domesticated and, as livestock, they provid ...
used in advertisements for
Camel-brand cigarettes.
Example
type 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" "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 also
*
Join-calculus
References
External links
*
Join-calculus language
High-level programming languages
Functional languages
Object-oriented programming languages
Concurrent programming languages
OCaml programming language family
Programming languages created in 1999
Software using the GNU Lesser General Public License
Articles with example OCaml code
{{Prog-lang-stub