Concurrent ML
Appearance
Concurrent ML (CML) is a concurrent extension of the Standard ML programming language.
Sample Code
Here is sample code to print "hello, world" to the console. It spawns a thread which creates a channel for strings. This thread then spawns another thread which prints the first string that is received on the channel, and then sends the "hello, world" string on the channel. It uses SML/NJ and CML:
cml_test.cm:
Library
structure Main
is
cml_test.sml
$cml/cml.cm
$/basis.cm
cml_test.sml:
structure Main =
struct
open CML
fun test () =
(
let val c : string chan = channel () in
spawn (fn () => TextIO.print (recv (c)));
send (c, "hello, world\n");
exit ()
end
)
fun hello () = RunCML.doit
(
(fn () => ignore (spawn test)),
NONE
)
end
Running:
$ sml cml_test.cm Standard ML of New Jersey v110.55 [built: Mon Jan 16 16:54:23 2006] [scanning cml_test.cm] [parsing (cml_test.cm):cml_test.sml] [library $cml/cml.cm is stable] [library $cml/cml-internal.cm is stable] [library $cml/core-cml.cm is stable] - Main.hello (); [autoloading] [autoloading done] hello, world val it = 1 : OS.Process.status