Concurrent ML

From Wikipedia, the free encyclopedia
Jump to: navigation, search

Concurrent ML (CML) is a concurrent extension of the Standard ML programming language.

Sample Code[edit]

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. 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):

       structure Hello


   structure Hello =
       open CML
       fun hello () =
           let val c : string chan = channel ()
               spawn (fn () => TextIO.print (recv c));
               send (c, "hello, world\n");
               exit ()
       fun main (name, argv) =
           RunCML.doit (fn () => ignore (spawn hello), NONE)


   $ ml-build Hello.main
   Standard ML of New Jersey v110.60 [built: Mon Nov 27 14:19:21 2006]
   [library $cml/ is stable]
   [library $cml/ is stable]
   [parsing (]
   [creating directory .cm/SKEL]
   [library $cml/ is stable]
   [library $cml/ is stable]
   [library $SMLNJ-BASIS/ is stable]
   [compiling (]
   [creating directory .cm/GUID]
   [creating directory .cm/x86-unix]
   [code: 2170, data: 42, env: 2561 bytes]
   [scanning (]
   [parsing (]
   [compiling (]
   [code: 309, data: 37, env: 42 bytes]
   $ heap2exec cml_test.x86-linux cml_test
   $ ./cml_test
   hello, world

External links[edit]