next up previous contents
Next: Modules and compilation units Up: Moscow ML Owner's Manual Previous: Core language and libraries

The interactive system

 

The interactive system mosml is invoked simply by typing mosml at the command line:

program81

The interactive system can be terminated by typing quit(); and newline, or control-D (under Unix) or control-Z and newline (under DOS). Type `help "";' for help on built-in functions.

Invoking the interactive system with command line arguments

program85

is equivalent to invoking mosml and, when Moscow ML has started, entering

program90

On-line help

 

In a mosml session, you may type help "lib"; for an overview of built-in function libraries. To get help on a particular identifier, such as fromString, type

program99

This will produce a menu of all library structures which contain the identifier fromstring (disregarding the lowercase/uppercase distinction):

program102

Choosing a number from this menu will invoke the help browser on the desired structure, e.g. Int. The help browser is primitive but easy to use. It works best with a window size of 24 lines.

The texts accessed by help are found in directory mosml/lib. For instance, all List functions are described in file mosml/lib/List.sig.

Editing and running ML programs

 

Unix and Emacs
You may run mosml as a subshell under Emacs. You should use the mosml-version of the SML mode for Emacs; see file mosml/utility/emacs for instructions. In case of errors, Emacs can interpret mosml's error messages and jump to the offending piece of source code. This is very convenient.

Window systems
In a window-oriented system, such as MacOS, MS Windows, or the X window system, you may run mosml in one window and edit source code in another. After (re-)editing the source file, you must issue a use command in the mosml window.

MS DOS
You may use the simple edit script to invoke an editor from inside a mosml session; see file mosml\utility\dosedit for instructions. You will not need to quit the mosml session to edit a source file, and the script will automatically reload the newly edited file.

Command-line options

 

-I directory

Specify the default directories to be searched by use, compile and load. A call to use, compile or load will first search the current directory, then all directories specified by option `-I' in order of appearance from left to right, and finally the standard library directory.

-valuepoly

Specify that the type checker should use `value polymorphism'; see Section 7. The default.

-imptypes

Specify that the type checker should distinguish imperative and applicative type variables, generalize all applicative type variables, and generalize imperative type variables only in non-expansive expressions. See Section 7.

-P unit-set

Determines which library units will be included and open at compile-time, and which library units will be linked in at link-time:

-P default
This provides an initial environment for the new Basis Library, compatible with future versions of SML/NJ. The units Array, Char, List, String, and Vector will be loaded, and units Char, List, and String will be partially opened. This is the default.

-P sml90
This provides an initial environment which is upwards compatible with that of the Definition of Standard ML and with pre-1.30 releases of Moscow ML. In particular, the functions chr, explode, implode, and ord work on strings, not characters. The new versions of these functions are still available as Char.chr, Char.ord, String.explode, and String.implode. The math functions and input-output facilities required by the Definition [6, Appendix C and D,] are available at top-level. In addition the same (new) libraries are loaded as with -P default.

-P nj93
This provides a top-level environment which is mostly compatible with that of SML/NJ 0.93. The functions app, ceiling, chr, dec, explode, fold, hd, implode, inc, max, min, nth, nthtail, ord, ordof, revapp, revfold, substring, tl, and truncate have the same type and meaning as in SML/NJ 0.93. Note that this is incompatible with future versions of SML/NJ. The math functions and input-output facilities required by the Definition [6, Appendix C and D,] are available at top-level. In addition the same (new) libraries are loaded as with -P default. This option does not imply -valuepoly or -imptypes.

-P full
This loads all the libraries marked F in the library list (see [8]), and partially opens the Char, List, and String units.

-P parsing
Loads the full libraries, plus support libraries for lexers and parsers generated by mosmllex (Section 9) and mosmlyac (Section 10).

-P none
No library units are loaded or opened initially.

Additional library units can loaded into the interactive system by using the load function; see Section 3.4 below.

-stdlib stdlib-directory

Specify the standard library directory to be stdlib-directory. The default standard library is usually mosml/lib under Unix and c:\mosml\lib under DOS.

Non-standard primitives in the interactive system

 

The following non-standard primitives are defined in unit Meta, loaded (and open by default) only in the interactive system. Hence these primitives cannot be used from source files which are compiled separately. The functions compile and load deal with Moscow ML compilation units; see Section 4.

printVal : 'a -> 'a

printVal is a polymorphic function provided as a quick debugging aid. This is an identity function, which as a side-effect prints its argument to standard output exactly as it would be printed at top-level. Output is flushed immediately. For printing strings, the function print is probably more useful than printVal.

printDepth : int ref

This variable determines the depth (in terms of nested constructors, records, tuples, lists, and vectors) to which values are printed by the top-level value printer and the function printVal. The components of the value whose depth is greater than printDepth are printed as `#'. The initial value of printDepth is 20. This value can be changed by the user's program at any moment.

printLength : int ref

This variable determines the way in which list values are printed by the top-level value printer and the function printVal. If the length of a list is greater than printLength, only the first printLength elements are printed, and the remaining elements are printed as `...'. The initial value of printLength is 200. This value can be changed by the user's program at any moment.

quit : unit -> unit

Evaluating quit() quits Moscow ML immediately.

installPP : (ppstream -> 'a -> unit) -> unit

Evaluating installPP pp installs the prettyprinter pp at type ty, provided pp has type ppstream -> ty -> unit. The type ty must be a nullary (parameter-less) type constructor representing a datatype, either built-in (such as bool) or user-defined. Whenever a value of type ty is about to be printed by the interactive system, and whenever function printVal is invoked on an argument of type ty, the prettyprinter pp will be invoked to print it.

The prettyprinter pp must not call the flush_ppstream function. See library unit PP for more information on prettyprinters.

use : string -> unit

Evaluating use "f" causes ML declarations to be read from file f as if they were entered from the console. A file loaded by use may, in turn, evaluate calls to use. For best results, use use only at top level, or at top level within a use'd file.

compile : string -> unit

Evaluating compile "U.sig" will compile and elaborate the unit signature in file U.sig, producing a compiled signature file U.ui. During compilation, the compiled signatures of other units will be accessed if they are mentioned in U.sig.

Evaluating compile "U.sml" will elaborate and compile the unit body in file U.sml, producing a bytecode file U.uo. If there is an explicit signature U.sig, then file U.ui must exist, and the unit body must match the signature. If there is no U.sig, then an inferred signature file U.ui will be produced also. No evaluation takes place. During compilation, the compiled signatures of other units will be accessed if they are mentioned in U.sml.

The declared identifiers will be reported if verbose is true (see below); otherwise compilation will be silent. In any case, compilation warnings are reported, and compilation errors abort the compilation and raise the exception Fail with a string argument.

load : string -> unit

Evaluating load "U" will load and evaluate the compiled unit body from file U.uo. The resulting values are not reported, but exceptions are reported, and cause evaluation and loading to stop. If U is already loaded, then load "U" has no effect. If any other unit is mentioned by U but not yet loaded, then it will be loaded automatically before U.

After loading a unit, it can be opened with open U. Opening it at top-level will list the identifiers declared in the unit.

When loading U, it is checked that the signatures of units mentioned by U agree with the signatures used when compiling U, and it is checked that the signature of U has not been modified since U was compiled; these checks are necessary for type safety. The exception Fail is raised if the signature checks fail, or if the file containing U or a unit mentioned by U does not exist.

loadOne : string -> unit

Evaluating loadOne "U" is similar to load " U", but raises exception Fail if U is already loaded or if some unit mentioned by U is not yet loaded. That is, it does not automatically load any units mentioned by U. It performs the same signature checks as load.

exnName : exn -> string

Returns a name for the exception constructor in the exception. Never raises an exception itself. The name returned may be that of any exception constructor aliasing with exn. For instance, let exception E1; exception E2 = E1 in exnName E2 end may evaluate to "E1" or "E2".

exnMessage : exn -> string

Formats and returns a message corresponding to the exception. For the exceptions defined in the SML Basis Library, the message will include the argument carried by the exception.

verbose : bool ref

Determines whether the signature inferred by a call to compile will be printed. The printed signature follows the syntax of Moscow ML signatures, so the output of compile "U.sml" can be edited to subsequently create file U.sig. The default value is false.

quotation : bool ref

Determines whether quotations and antiquotations are permitted in declarations entered at top-level and in files compiled with compile; see Section 8 for a brief explanation. When quotation is false (the default), the backquote character is an ordinary symbol which can be used in ML symbolic identifiers. When quotation is true, the backquote character is illegal in symbolic identifiers, and a quotation `a b c` will be evaluated to an object of type 'a frag list.

valuepoly : bool ref

Determines whether the type checker should use `value polymorphism'; see Section 7. Command-line option -valuepoly sets valuepoly to true (the default), whereas option -imptypes sets valuepoly to false; see Sections 3.3 and 5.2.

system : string -> int

Evaluating system "com" causes the command com to be executed by the operating system. If a non-zero integer is returned, this must indicate that the operating system has failed to execute the command. Under MS DOS, the integer returned always equals 0.


next up previous contents
Next: Modules and compilation units Up: Moscow ML Owner's Manual Previous: Core language and libraries

Moscow ML 1.42