(S)ML-97 Examples

LA home
Computing
 Algorithms
 Bioinformatics
 FP,  λ
 Logic,  π
 MML
 Prog.Langs

FP
 SML
  SML97
   Basics
   High O.Fn
   Laziness
   Structures
   Conts.
   sem'.toy
[Basics] of SML.
 
Hello world:
print "hello world\n"

(* SML hello world program, LA 11/4/2005 *)

use:
ne> sml
Standard ML of ...
- use "hello.sml";
[opening hello.sml]
hello world
val it = () : unit
val it = () : unit
-<CTRL>d
- ne>
 
cat:
open TextIO;        (* i.e. the I/O library *)

fun cat fileName =
  let
    fun f inS =
      if endOfStream inS then
           ( closeIn inS; print "\n" )
      else ( print (inputN(inS, 1));  f inS )
  in f(openIn fileName)
  end;

(* e.g. *) cat "cat.sml";

(* Copy file to std output, L.A., 11/4/2005 *)
(* Also see I/O, Ch 4,                      *)
(* Ullman "Elements of ML Programming" 1998 *)

 
[Big Ints], more than 32- or 64-bits.
 
[High-Order Functions] accept functions as parameters and/or return functions as results.
 
[Parser] (recursive descent) for expressions.
 
[Lazy data types] are not standard in SML but they can be implemented in the language.
 
[Structures, signatures, functors], struct, sig.
 
[Continuations] can be used to implement non-standard control mechanisms.
 
[Fixed-point operator, `Y'], note that Y does not refer to itself within its body, nor does the local function Ggg; one could rewrite Y to consist of only anonymous functions. Also see [λ/Y].
 
[semantics.toy] direct denotational sematics of a toy imperative language expressed in SML-97
 

Further Reading:

[λ-calculus].
[Bibliography].
window on the wide world:

Computer Science Education Week

Linux
 Ubuntu
free op. sys.
OpenOffice
free office suite,
ver 3.4+

The GIMP
~ free photoshop
Firefox
web browser
FlashBlock
like it says!

SML:
:: cons
[x1,...] list
[ ] list
@ append
fn =>  &lambda .
: has type

© L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated),
Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University,
was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.)
Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Friday, 25-Apr-2014 04:43:12 EST.