Concurrent ML
Encyclopedia
Concurrent ML is a concurrent
extension of the Standard ML
programming language.
which creates a channel for strings
. This thread then spawns another thread which prints the first string that is received on the channel. The former thread then sends the "hello, world\n" string on the channel. It uses SML/NJ
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):
cml_test.cm:
Library
structure Hello
is
$cml/basis.cm
$cml/cml.cm
cml_test.sml
cml_test.sml:
structure Hello =
struct
open CML
fun hello =
let val c : string chan = channel
in
spawn (fn => TextIO.print (recv c));
send (c, "hello, world\n");
exit
end
fun main (name, argv) =
RunCML.doit (fn => ignore (spawn hello), NONE)
end
Running:
$ ml-build cml_test.cm Hello.main
Standard ML of New Jersey v110.60 [built: Mon Nov 27 14:19:21 2006]
[scanning cml_test.cm]
[library $cml/basis.cm is stable]
[library $cml/cml.cm is stable]
[parsing (cml_test.cm):cml_test.sml]
[creating directory .cm/SKEL]
[library $cml/cml-internal.cm is stable]
[library $cml/core-cml.cm is stable]
[library $SMLNJ-BASIS/basis.cm is stable]
[compiling (cml_test.cm):cml_test.sml]
[creating directory .cm/GUID]
[creating directory .cm/x86-unix]
[code: 2170, data: 42, env: 2561 bytes]
[scanning 18518-export.cm]
[scanning (18518-export.cm):cml_test.cm]
[parsing (18518-export.cm):18518-export.sml]
[compiling (18518-export.cm):18518-export.sml]
[code: 309, data: 37, env: 42 bytes]
$ heap2exec cml_test.x86-linux cml_test
$ ./cml_test
hello, world
Concurrency (computer science)
In computer science, concurrency is a property of systems in which several computations are executing simultaneously, and potentially interacting with each other...
extension of the Standard ML
Standard ML
Standard ML 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 theorem provers.SML is a modern descendant of the ML...
programming language.
Sample Code
Here is sample code to print "hello, world" to the console. It spawns a threadThread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
which creates a channel for strings
String (computer science)
In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set or alphabet....
. This thread then spawns another thread which prints the first string that is received on the channel. The former thread then sends the "hello, world\n" string on the channel. It uses SML/NJ
Standard ML of New Jersey
Standard ML of New Jersey is a compiler and programming environment for Standard ML. Aside from its runtime system, which is written in C, SML/NJ is written in Standard ML...
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):
cml_test.cm:
Library
structure Hello
is
$cml/basis.cm
$cml/cml.cm
cml_test.sml
cml_test.sml:
structure Hello =
struct
open CML
fun hello =
let val c : string chan = channel
in
spawn (fn => TextIO.print (recv c));
send (c, "hello, world\n");
exit
end
fun main (name, argv) =
RunCML.doit (fn => ignore (spawn hello), NONE)
end
Running:
$ ml-build cml_test.cm Hello.main
Standard ML of New Jersey v110.60 [built: Mon Nov 27 14:19:21 2006]
[scanning cml_test.cm]
[library $cml/basis.cm is stable]
[library $cml/cml.cm is stable]
[parsing (cml_test.cm):cml_test.sml]
[creating directory .cm/SKEL]
[library $cml/cml-internal.cm is stable]
[library $cml/core-cml.cm is stable]
[library $SMLNJ-BASIS/basis.cm is stable]
[compiling (cml_test.cm):cml_test.sml]
[creating directory .cm/GUID]
[creating directory .cm/x86-unix]
[code: 2170, data: 42, env: 2561 bytes]
[scanning 18518-export.cm]
[scanning (18518-export.cm):cml_test.cm]
[parsing (18518-export.cm):18518-export.sml]
[compiling (18518-export.cm):18518-export.sml]
[code: 309, data: 37, env: 42 bytes]
$ heap2exec cml_test.x86-linux cml_test
$ ./cml_test
hello, world