| SML  | http://www.standardml.org/ | 
| Hello World | Michael Neumann | 
| 
print "Hello World\n";
 | 
| Prints "Hello World" onto the
screen. | 
| Squares (1) | Michael Neumann | 
| fun iter (a,b) = if a <= b then (print(Int.toString(a*a) ^ " "); iter(a+1,b) ) else print "\n"; iter(1,10); | 
| Outputs the squares from 1 to
10. | 
| Squares (2) | Michael Neumann | 
| fun iter 0 = "" | iter n = (iter(n-1); print(Int.toString(n*n) ^ " "); "\n"); print(iter 10); | 
| Outputs the squares from 1 to
10. | 
| Word Tokenizer | Michael Neumann | 
| 
fun wordTokenizer (reader : (char, TextIO.StreamIO.instream) StringCvt.reader)
                  (strm : TextIO.StreamIO.instream) = let
  fun scan s (l: char list) (charState: bool) =
    case (reader s)
      of NONE => (l, s)
       | SOME (c, s) =>
         if Char.isAlpha c then scan s (l @ [c]) true
         else if charState then (l, s)
         else scan s l charState
  val (res, s) = scan strm [] false
in
  if res = [] then NONE
  else SOME (implode res, s)
end
fun lowerCaseFilter s =
  case s
    of NONE => NONE
     | SOME w => SOME (String.map Char.toLower w)
fun main (cmd:string, args:string list):OS.Process.status = let
  val (fileName::_) = args
  val ins = TextIO.openIn fileName
  val ws = lowerCaseFilter o TextIO.scanStream wordTokenizer
  fun loop () = case ws ins
                  of NONE => ()
                   | SOME word => (print word; print "\n"; loop ())
in
  loop ();
  0
end
fun test () =
  main ("tokenizer", ["tokenizer.sml"])
 | 
| Splits a given file into words and
outputs them. Makes use of SML streams. | 
| Hello World | SML/NJ | Michael Neumann | 
| 
(*
  To make a heap image of this file, load it into the 
  interactive compiler (you do this by starting "sml" at 
  the command line; then issue a 'use "thisfile.sml"'). 
  Type then:
    SMLofNJ.exportFn ("heapimage", main);
  Exit now the interactive compiler. To load the heap image,
  type (at the command line):
    sml @SMLload=/path/to/heapimage.ext
  (where ext is a platform dependend suffix, e.g. "x86-bsd", to
   distinguish heap images of different OSes and platforms)
*)
fun main (cmd:string, args:string list):OS.Process.status =
(
  print "Hello world\n";
  0
);
 | 
| Prints "Hello World" onto the
screen. |