Concurrent ML (CML) is a
concurrent extension of the
Standard ML
Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of ...
programming language characterized by its ability to allow programmers to create
composable communication
abstractions that are
first-class rather than built into the language. The design of CML and its primitive operations have been adopted in several other programming languages such as
GNU Guile
GNU Ubiquitous Intelligent Language for Extensions (GNU Guile) is the preferred extension language system for the GNU Project and features an implementation of the programming language Scheme. Its first version was released in 1993. In additio ...
,
Racket,
and Manticore.
Concepts
Many programming languages that support concurrency offer
communication channels that allow the exchange of values between
processes
A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic.
Things called a process include:
Business and management
*Business process, activities that produce a specific se ...
or
threads
Thread may refer to:
Objects
* Thread (yarn), a kind of thin yarn used for sewing
** Thread (unit of measurement), a cotton yarn measure
* Screw thread, a helical ridge on a cylindrical fastener
Arts and entertainment
* ''Thread'' (film), 2016 ...
running concurrently in a system. Communications established between processes may follow a specific protocol, requiring the programmer to write functions to establish the required pattern of communication. Meanwhile, a communicating system often requires establishing multiple channels, such as to multiple
servers, and then choosing between the available channels when new data is available. This can be accomplished using
polling
Poll, polled, or polling may refer to:
Figurative head counts
* Poll, a formal election
** Election verification exit poll, a survey taken to verify election counts
** Polling, voting to make decisions or determine opinions
** Polling places o ...
, such as with the
select operation on Unix systems.
Combining both application-specific protocols and multi-party communication may be complicated due to the need to introduce polling and checking for
blocking within a pre-existing protocol. Concurrent ML solves this problem by reducing this
coupling
A coupling is a device used to connect two shafts together at their ends for the purpose of transmitting power. The primary purpose of couplings is to join two pieces of rotating equipment while permitting some degree of misalignment or end mov ...
of programming concepts by introducing synchronizable ''events''.
Events are a first-class abstraction that can be used with a synchronization operation (called in CML and Racket) in order to potentially block and then produce some value resulting from communication (for example, data transmitted on a channel).
In CML, events can be combined or manipulated using a number of primitive operations. Each primitive operation constructs a new event rather than modifying the event in-place, allowing for the construction of compound events that represent the desired communication pattern. For example, CML allows the programmer to combine several sub-events in order to create a compound event that can then make a non-deterministic choice of one of the sub-events. Another primitive creates a new event that will modify the value resulting from synchronization on the original event. These events embody patterns of communication that, in a non-CML language, would typically be handled using a polling loop or function with handlers for each kind of event.
Hello world
Here is a program that prints to the console. It spawns one
thread
Thread may refer to:
Objects
* Thread (yarn), a kind of thin yarn used for sewing
** Thread (unit of measurement), a cotton yarn measure
* Screw thread, a helical ridge on a cylindrical fastener
Arts and entertainment
* ''Thread'' (film), 2016 ...
with a channel for
strings, and another thread which prints a string received on the channel. It uses
SML/NJ
Standard ML of New Jersey (SML/NJ; Standard Meta-Language of New Jersey) is a free and open-source compiler and programming environment for the Standard ML programming language. Aside from its runtime system, which is written in C, SML/NJ is writ ...
and CML. (Note that the heap name will be different on non linux-x86 platforms; you may need to change the line with "cml_test.x86-linux" to something different.)
External links
The language homepage
References
{{reflist
Programming constructs
Programming language design
Concurrent programming languages
ML programming language family
Programming languages created in the 1990s