JoCaml

Last updated
JoCaml
Paradigms Multi-paradigm: functional, imperative
Family ML: Caml: OCaml
Developer Inria
Stable release
4.01 / March 2014;10 years ago (2014-03)
OS Cross-platform
License LGPL
Website jocaml.inria.fr

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.

Contents

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.

Example

typecoins=Nickel|Dimeanddrinks=Coffee|Teaandbuttons=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).   *)defput(s)=print_endlines;0(* STOP *);;(* put: string Join.chan *)defgive(d)=matchdwithCoffee->put("Coffee")|Tea->put("Tea");;(* give: drink Join.chan *)defrefund(v)=lets=Printf.sprintf"Refund %d"vinput(s);;(* refund: int Join.chan *)letnew_vendinggiverefund=letvend(cost:int)(credit:int)=ifcredit>=costthen(true,credit-cost)else(false,credit)indefcoin(Nickel)&value(v)=value(v+5)&replytocoinorcoin(Dime)&value(v)=value(v+10)&replytocoinorbutton(BCoffee)&value(v)=letshould_give,remainder=vend10vin(ifshould_givethengive(Coffee)else0(* STOP *))&value(remainder)&replytobuttonorbutton(BTea)&value(v)=letshould_give,remainder=vend5vin(ifshould_givethengive(Tea)else0(* STOP *))&value(remainder)&replytobuttonorbutton(BCancel)&value(v)=refund(v)&value(0)&replytobuttoninspawnvalue(0);coin,button(* coin, button: int -> unit *);;(* new_vending: drink Join.chan -> int Join.chan -> (int->unit)*(int->unit) *)letccoin,cbutton=new_vendinggiverefundinccoin(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

$ jocamlcexample.ml-otest$ ./test CoffeeTeaRefund 5

See also

Related Research Articles

In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.

<span class="mw-page-title-main">Integral</span> Operation in mathematical calculus

In mathematics, an integral is the continuous analog of a sum, which is used to calculate areas, volumes, and their generalizations. Integration, the process of computing an integral, is one of the two fundamental operations of calculus, the other being differentiation. Integration was initially used to solve problems in mathematics and physics, such as finding the area under a curve, or determining displacement from velocity. Usage of integration expanded to a wide variety of scientific fields thereafter.

OCaml is a general-purpose, high-level, multi-paradigm programming language which extends the Caml dialect of ML with object-oriented features. OCaml was created in 1996 by Xavier Leroy, Jérôme Vouillon, Damien Doligez, Didier Rémy, Ascánder Suárez, and others.

In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function together with an environment. The environment is a mapping associating each free variable of the function with the value or reference to which the name was bound when the closure was created. Unlike a plain function, a closure allows the function to access those captured variables through the closure's copies of their values or references, even when the function is invoked outside their scope.

<span class="mw-page-title-main">F Sharp (programming language)</span> Microsoft programming language

F# is a general-purpose, high-level, strongly typed, multi-paradigm programming language that encompasses functional, imperative, and object-oriented programming methods. It is most often used as a cross-platform Common Language Infrastructure (CLI) language on .NET, but can also generate JavaScript and graphics processing unit (GPU) code.

<span class="mw-page-title-main">Nickel (United States coin)</span> Current denomination of United States currency

A nickel is a five-cent coin struck by the United States Mint. Composed of cupronickel, the piece has been issued since 1866. Its diameter is 0.835 inches (21.21 mm) and its thickness is 0.077 inches (1.95 mm).

<span class="mw-page-title-main">Dime (United States coin)</span> Current denomination of United States currency

The dime, in United States usage, is a ten-cent coin, one tenth of a United States dollar, labeled formally as "one dime". The denomination was first authorized by the Coinage Act of 1792.

<span class="mw-page-title-main">Two-cent piece (United States)</span> Coin of the United States (1864–1873)

The two-cent piece was produced by the Mint of the United States for circulation from 1864 to 1872 and for collectors in 1873. Designed by James B. Longacre, there were decreasing mintages each year, as other minor coins such as the nickel proved more popular. It was abolished by the Mint Act of 1873.

In functional programming, a monad is a structure that combines program fragments (functions) and wraps their return values in a type with additional computation. In addition to defining a wrapping monadic type, monads define two operators: one to wrap a value in the monad type, and another to compose together functions that output values of the monad type. General-purpose languages use monads to reduce boilerplate code needed for common operations. Functional languages use monads to turn complicated sequences of functions into succinct pipelines that abstract away control flow, and side-effects.

In computer programming, a callback is a function that is stored as data and designed to be called by another function – often back to the original abstraction layer.

Concurrent computing is a form of computing in which several computations are executed concurrently—during overlapping time periods—instead of sequentially—with one completing before the next starts.

<span class="mw-page-title-main">Barber coinage</span> American coins

The Barber coinage consists of a dime, quarter, and half dollar designed by United States Bureau of the Mint Chief Engraver Charles E. Barber. They were minted between 1892 and 1916, though no half dollars were struck in the final year of the series.

In computing, a meta-circular evaluator (MCE) or meta-circular interpreter (MCI) is an interpreter which defines each feature of the interpreted language using a similar facility of the interpreter's host language. For example, interpreting a lambda application may be implemented using function application. Meta-circular evaluation is most prominent in the context of Lisp. A self-interpreter is a meta-circular interpreter where the interpreted language is nearly identical to the host language; the two terms are often used synonymously.

The join-calculus is a process calculus developed at INRIA. The join-calculus was developed to provide a formal basis for the design of distributed programming languages, and therefore intentionally avoids communications constructs found in other process calculi, such as rendezvous communications, which are difficult to implement in a distributed setting. Despite this limitation, the join-calculus is as expressive as the full π-calculus. Encodings of the π-calculus in the join-calculus, and vice versa, have been demonstrated.

<span class="mw-page-title-main">2 euro coin</span> Highest-value euro coin

The 2 euro coin (€2) is the highest-value euro coin and has been used since the introduction of the euro in 2002. The coin is made of two alloys: the inner part of nickel brass, the outer part of copper-nickel. All coins have a common reverse side and country-specific national sides. The coin has been used since 2002, with the present common side design dating from 2007.

<span class="mw-page-title-main">Hume (programming language)</span> Functional programming language

Hume is a functionally based programming language developed at the University of St Andrews and Heriot-Watt University in Scotland since the year 2000. The language name is both an acronym meaning 'Higher-order Unified Meta-Environment' and an honorific to the 18th-century philosopher David Hume. It targets real-time computing embedded systems, aiming to produce a design that is both highly abstract, and yet allows precise extraction of time and space execution costs. This allows guaranteeing the bounded time and space demands of executing programs.

The fundamental theorem of calculus is a theorem that links the concept of differentiating a function with the concept of integrating a function. The two operations are inverses of each other apart from a constant value which depends on where one starts to compute area.

<span class="mw-page-title-main">James B. Longacre</span> American portraitist and engraver (1794–1869)

James Barton Longacre was an American portraitist and engraver, and the fourth chief engraver of the United States Mint from 1844 until his death. Longacre is best known for designing the Indian Head cent, which entered commerce in 1859, and for the designs of the Shield nickel, Flying Eagle cent and other coins of the mid-19th century.

Join-patterns provides a way to write concurrent, parallel and distributed computer programs by message passing. Compared to the use of threads and locks, this is a high level programming model using communication constructs model to abstract the complexity of concurrent environment and to allow scalability. Its focus is on the execution of a chord between messages atomically consumed from a group of channels.

In computer programming, the async/await pattern is a syntactic feature of many programming languages that allows an asynchronous, non-blocking function to be structured in a way similar to an ordinary synchronous function. It is semantically related to the concept of a coroutine and is often implemented using similar techniques, and is primarily intended to provide opportunities for the program to execute other code while waiting for a long-running, asynchronous task to complete, usually represented by promises or similar data structures. The feature is found in C#, C++, Python, F#, Hack, Julia, Dart, Kotlin, Rust, Nim, JavaScript, Swift and Zig.

References

  1. Ma, Qin; Maranget, Luc (2004). "Compiling Pattern-Matching in Join-Patterns". Proceedings of the 15th International Conference on Concurrency Theory. LNCS. 3170. Springer-Verlag.
  2. Ma, Qin; Maranget, Luc (2008). "Algebraic Pattern Matching in Join Calculus". Logical Methods in Computer Science. 4 (1). arXiv: 0802.4018 . Bibcode:2008arXiv0802.4018M. doi:10.2168/LMCS-4(1:7)2008. S2CID   15873901.
  3. Conchon, S.; Le Fessant, F. (1999). "Jocaml: Mobile agents for Objective-Caml". Proceedings of the First and Third International Symposium on Agent Systems Applications, and Mobile Agents. pp. 22–29. doi:10.1109/ASAMA.1999.805390. ISBN   0-7695-0342-X. S2CID   14355301.
  4. Louis Mandel; Luc Maranget. "Programming in JoCaml". Inria research report 6261.