.TH ML 1 "8th Feb 1990"
.SH NAME
ml \- Edinburgh Standard ML core language compiler
.SH SYNOPSIS
.B ml
.SH DESCRIPTION
.IX  ml  "ml compiler"  ""  "ml compiler"
.LP
.B ml
starts the Edinburgh ML compiler.  The compiler
interactively accepts input from the standard input 
and writes to the standard output.  The compiler
exits when the standard input end of file is reached (
.I Control-D
on many UNIX systems).
.LP
.B ml
prompts for input with the "-" prompt.  ML declarations can then
be typed in followed by a ";".  Expressions may be spread over many
lines, 
.B ml 
prompts with "=" on all lines after the first line  in a
declaration.  Successful declarations are reported with a ">"
prompt, error messages describe unsuccessful declarations.
.LP
Example ML session:

.sp
.ps 9
.vs 10
.nf
.if !\n(cW .cs R 18
.in +2

\- 1;
> 1 : int


\- val (a,b) =
=  (5+3,"x" ^ "y");
> val b = "xy" : string
  val a = 8 : int

\- fun pair_of x = (x,x);
> val pair_of = fn : 'a \-> ('a * 'a)

\- fun badfunction = 1;

Parse error:
Was expecting a Function-binding, but only got a Pattern-variable

In:  ... fun badfunction <?> =

.in -2
.if !\n(cW .cs R
.fi
.ps 10
.vs 12
.sp
Edinburgh ML also provides an exception traceback mechanism, for
example (See the description of the value 
.I Debug
in 
.I BUILT\-IN VALUES
below).

.sp
.ps 9
.vs 10
.nf
.if !\n(cW .cs R 18
.in +2
\- fun ridiculous (_::t) = let val x = f t in x end;
***Warning:  Patterns in Match not exhaustive:  (_ :: t)=>(let % = % in x)
> val ridiculous = fn : ('a list) \-> 'b
\- ridiculous [1,2,3,4,5,6,7];
Exception traceback
returning through  f    (7 times)
returning through  ridiculous
returning to top level
Warning: optimisations enabled \- some functions may be missing from the trace
Exception: Match  raised
.in -2
.if !\n(cW .cs R
.fi
.ps 10
.vs 12


.SH "BUILT-IN VALUES"
Besides the standard pervasives, the following built-in values are
provided:

(* string functions *)
.sp
val makestring: 'a -> string 
.br
.in +2
overloaded: defined for types int,real,bool
.in -2
.sp
exception Substring
.br
val substring: (string * int * int) -> string
.br
.in +2
returns the substring starting from character position
of first int argument (0 is first in string) with length of
second int argument - raises Substring if string is too small 
.in -2
.sp
val explodeascii: string -> int list
.br
.in +2
(* fun explodeascii s = map ord (explode s) *)
.in -2
.sp
exception ImplodeAscii
.br
val implodeascii: int list -> string
.br
.in +2
returns a string corresponding to the argument list of ascii
codes.  raises ImplodeAscii if a list element is <0 or >255 
.in -2
.sp
(* integer functions *)
.sp
val min: int * int -> int
.br
val max: int * int -> int
.sp
(* list functions *)
.sp
exception Hd and Tl
val hd: 'a list -> 'a
val tl: 'a list -> 'a list
.br
.in +2
hd and tl return the head and tail of a list respectively,
respectively raising Hd and Tl if applied to empty lists 
.in -2
.sp
val null: 'a list -> bool
.br
.in +2
returns true is arg is the empty list, false otherwise
.in -2
.sp
val fold: (('a * 'b) -> 'b) -> (('a list) -> ('b -> 'b))
.in +2
.br
list accumulator
.in -2
.sp
exception Nth
.br
val nth: (('a list) * int) -> 'a
.br
.in +2
returns the nth (0th is first element) of a list -
raises Nth if int arg is out of range 
.in -2
.sp
val exists: (('a -> bool) * ('a list)) -> bool
.br
.in +2
returns true if the function f(:'a -> bool ) returns true
when applied to at least one member of the list 
.in -2
.sp
(* ref functions *)
.sp
val inc: (int ref) -> unit
.br
val dec: (int ref) -> unit
.br
.in +2
increment / decrement an int ref by 1 
.in -2
.sp
(* system functions *)
.sp
val stdio: unit -> (instream * outstream)
.br
.in +2
generates new standard input/output streams
.in -2
.sp
val input_line: instream -> string
.br
.in +2
reads a line from instream and returns as a string
.in -2
.sp
val execute: string -> (instream * outstream)
.br
.in +2
UNIX only - forks a process (named by the string arg)
from the shell and returns input and output streams for
that process 
.in -2
.sp
val file_exists: string -> bool
.br
.in +2
may use relative or full pathnames for filename in UNIX *)
.in -2
.sp
val use: string -> unit
.br
.in +2
loads and compiles the SML programs in the named file
.in -2
.sp
val system: string -> unit
.br
.in +2
passes the string to the operating system command interpreter for execution
.in -2
.sp
val CpuTime: unit -> int
.br
.in +2
returns milliseconds used by process
.in -2
.sp
val ExportML: (string * string * (string list)) -> unit
.br
.in +2
create a new saved state for SML:
.br
.in +2
arg 1 - filename for saved state
.br
arg 2 - startup message
.br
arg 3 - list of files to be "use"d on startup 
.in -2
.in -2
.sp
val Debug: {CheckMatchLimit: int ref, Optimise: bool ref, ...}
.br
Debug is a record containing references which determine the operation 
of the  compiler.  Of the various fields of Debug, the most useful
(for the user) are:
.in +2
CheckMatchLimit: int ref
.br
.in +2
The exhaustiveness checking of ML patterns is implemented using an
exponential algorithm.  This field limits how much time is spent on
checking for exhaustiveness - if this limit is exceeded, the compiler
issues a warning to the effect that the patterns may be inexhaustive
but it has given up the check.  Increasing the value of
CheckMatchLimit forces the compiler to spend more time in this check.
.in -2
.br
Optimise: bool ref
.br
.in +2
This flag determines the optimisation carried out in the code
generation phase of the compiler.  A value 
.I true
(default) enables inline expansion of functions, tail recursion
optimisations etc.  Optimisations should only be disabled to gain an
accurate exception trace.  
.in -2

.SH INTERACTIVE LINE EDITING

The default ML system supports a limited form of line editing based on
the  GNU bash Readline library.  The line editing is exactly like that
of bash and is similar to that of GNU, other emacses and tcsh.  The
line editing can also be made to behave similarly to vi.

Forward-char, backward-char, forward-word, backward-word, undo,
beginning-of-line, end-of-line, previous-line, next-line,
reverse-search, etc.  Try them!

To switch between GNU style editing and vi style editing type M-C-j
(ESC Ctrl-j).  In future releases the bash readline library will be
distributed with the ML system.


.SH SEE ALSO

.I The Definition of Standard ML,
Robin Milner, Mads Tofte, Robert Harper,  MIT press, 1990.
