ML

Section: User Commands (1)
Updated: 8th Feb 1990
Index Return to Main Contents
 

NAME

ml - Edinburgh Standard ML core language compiler  

SYNOPSIS

ml  

DESCRIPTION

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 ( Control-D on many UNIX systems).

ml prompts for input with the "-" prompt. ML declarations can then be typed in followed by a ";". Expressions may be spread over many lines, 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.

Example ML session:


- 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 <?> =

Edinburgh ML also provides an exception traceback mechanism, for example (See the description of the value Debug in BUILT-IN VALUES below).

- 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

 

BUILT-IN VALUES

Besides the standard pervasives, the following built-in values are provided:

(* string functions *)

val makestring: 'a -> string
overloaded: defined for types int,real,bool

exception Substring
val substring: (string * int * int) -> string
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

val explodeascii: string -> int list
(* fun explodeascii s = map ord (explode s) *)

exception ImplodeAscii
val implodeascii: int list -> string
returns a string corresponding to the argument list of ascii codes. raises ImplodeAscii if a list element is <0 or >255

(* integer functions *)

val min: int * int -> int
val max: int * int -> int

(* list functions *)

exception Hd and Tl val hd: 'a list -> 'a val tl: 'a list -> 'a list
hd and tl return the head and tail of a list respectively, respectively raising Hd and Tl if applied to empty lists

val null: 'a list -> bool
returns true is arg is the empty list, false otherwise

val fold: (('a * 'b) -> 'b) -> (('a list) -> ('b -> 'b))
list accumulator

exception Nth
val nth: (('a list) * int) -> 'a
returns the nth (0th is first element) of a list - raises Nth if int arg is out of range

val exists: (('a -> bool) * ('a list)) -> bool
returns true if the function f(:'a -> bool ) returns true when applied to at least one member of the list

(* ref functions *)

val inc: (int ref) -> unit
val dec: (int ref) -> unit
increment / decrement an int ref by 1

(* system functions *)

val stdio: unit -> (instream * outstream)
generates new standard input/output streams

val input_line: instream -> string
reads a line from instream and returns as a string

val execute: string -> (instream * outstream)
UNIX only - forks a process (named by the string arg) from the shell and returns input and output streams for that process

val file_exists: string -> bool
may use relative or full pathnames for filename in UNIX *)

val use: string -> unit
loads and compiles the SML programs in the named file

val system: string -> unit
passes the string to the operating system command interpreter for execution

val CpuTime: unit -> int
returns milliseconds used by process

val ExportML: (string * string * (string list)) -> unit
create a new saved state for SML:
arg 1 - filename for saved state
arg 2 - startup message
arg 3 - list of files to be "use"d on startup

val Debug: {CheckMatchLimit: int ref, Optimise: bool ref, ...}
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: CheckMatchLimit: int ref
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.
Optimise: bool ref
This flag determines the optimisation carried out in the code generation phase of the compiler. A value true (default) enables inline expansion of functions, tail recursion optimisations etc. Optimisations should only be disabled to gain an accurate exception trace.

 

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.

 

SEE ALSO

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


 

Index

NAME
SYNOPSIS
DESCRIPTION
BUILT-IN VALUES
INTERACTIVE LINE EDITING
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 20:16:52 GMT, October 04, 2024