The Standard ML Basis Library

The SML90 structure

The SML90 structure provides the types and values available in older versions of SML. This allows code written under the old basis to be used with little or no change.

The required identifiers correspond to those specified in the Definition as part of the initial basis for which the equivalent is not provided in the new basis. Thus, since the map function is the same in both the old and new bases, it is not included in SML90. The real type is the exception to this rule. In the old basis, real was an equality type and allowed pattern matching. In addition, the basic arithmetic operators raised exceptions on exceptional conditions. These properties no longer hold, and the SML90 structure does not provide support for them.

In addition to the required identifiers, the structure may contain implementation-dependent substructures that provide the top-level bindings available in older versions of the implementation. For example, the SML90 might contain the substructure SMLNJ, which would contain the additional types, values and modules provided by the SML/NJ implementation.

This module is provided solely to allow programmers to continue to run old code in the new environment while, it is hoped, gradually rewriting the source to be compatible with the new environment. At some point, the SML90 structure will be considered obsolete and will be removed from the basis.


structure SML90 :> SML90


signature SML90


type instream
type outstream
exception Abs
exception Quot
exception Prod
exception Neg
exception Sum
exception Diff
exception Floor
exception Exp
exception Sqrt
exception Ln
exception Ord
exception Mod
exception Io of string
exception Interrupt
val sqrt : real -> real
val exp : real -> real
val ln : real -> real
val sin : real -> real
val cos : real -> real
val arctan : real -> real
val ord : string -> int
val chr : int -> string
val explode : string -> string list
val implode : string list -> string
val std_in : instream
val open_in : string -> instream
val input : (instream * int) -> string
val lookahead : instream -> string
val close_in : instream -> unit
val end_of_stream : instream -> bool
val std_out : outstream
val open_out : string -> outstream
val output : (outstream * string) -> unit
val close_out : outstream -> unit


type instream
type outstream
The types of input and output streams, respectively.

exception Abs
exception Quot
exception Prod
exception Neg
exception Sum
exception Diff
exception Floor
exception Exp
These exceptions are aliases for Overflow.

exception Sqrt

exception Ln

exception Ord

exception Mod
This is an alias for Div.

exception Io

exception Interrupt
This exception is never raised.

sqrt r
returns the square root of r, raising Sqrt if r is negative.

exp r
returns e(x), i.e., e raised to the xth power. Raises Exp is the resulting number is too large.

ln r
returns the natural logarithm of r, raising Ln if r is not positive.

sin r
cos r
return the sine and cosine, respectively, of r. These are equivalent to Math.sin and Math.cos.

arctan r
returns the arc tangent of r. This is equivalent to Math.atan.

ord s
chr i
returns the integer code of the first character in s and the string containing a single character whose code is i, respectively. The function ord raises Ord if s is empty. The function chr raises Chr if i < 0 or i > 255.

explode s
is the list of characters, represented as strings of size 1, in the string s.

implode l
is the concatenation of all the strings in l. This raises Size if the sum of all the sizes is greater than String.maxSize. The function is equivalent to String.concat.

is the standard input stream, open by default.

open_in s
opens the file named s for reading and returns the corresponding input stream. Raises Io if the file s cannot be opened for reading.

input (ins, i)
reads i characters from an input stream ins. If fewer than i characters remain before end of file, return them. Otherwise block until either i characters are available or end of Raises Io if ins has been closed.

lookahead ins
yields the next character from ins without removing it from the readable input, or the empty string if at end of file. Blocks if no character available but not at end of file.

close_in ins
closes the input stream ins.

end_of_stream ins
returns true if at end of stream

is the standard output stream, open by default.

open_out s
opens the file named ss$ for writing and returns the corresponding output stream. Raises Io if the file s cannot be opened for writing.

output (outs, s)
writes the string s to output stream outs. Raises Io if outs has been closed.

close_out outs
flushes and closes the output stream outs.


Since the I/O streams here and in TextIO are buffered, but may share low-level I/O primitives, mixing the use of both types of streams in an application may lead to unexpected results.

As noted above, this module only contains items not available in the new basis, or having different semantics. The following list gives the types that are the same in both the old and new bases.

eqtype unit
eqtype int
eqtype real
eqtype string
type exn
eqtype 'a ref
datatype bool = false | true
datatype 'a list = nil | :: of ('a * 'a list)

The top-level exceptions that are the same in the old and new bases are
exception Bind
exception Chr
exception Div
exception Match

We next give a list of the identical functions.
val map : ('a -> 'b) -> 'a list -> 'b list
val rev : 'a list -> 'a list
val not : bool -> bool
val ~ : num -> num
val abs : num -> num
val floor : real -> int
val real : int -> real
val size : string -> int
val ! : 'a ref -> 'a
val ref : 'a -> 'a ref
val / : real * real -> real
val div : int * int -> int
val mod : int * int -> int
val * : num * num -> num
val + : num * num -> num
val - : num * num -> num
val ^ : string * string -> string
val @ : ('a list * 'a list) -> 'a list
val = : 'a * 'a -> bool
val <> : 'a * 'a -> bool
val < : num * num -> bool
val > : num * num -> bool
val <= : num * num -> bool
val >= : num * num -> bool
val := : 'a ref * 'a -> unit
val o : ('a -> 'b) * ('c -> 'a) -> 'c -> 'b

The type schemas given for overloaded functions are those of the 1990 [CITE]Definition/. The num category includes int and real. The actual functions in the new basis have more extended schemas. For example, < is defined for string values as well as all varieties of integer, word and real. Additional information on these top-level types and values can be found in the Chapter 3.
[ INDEX | TOP | Parent | Root ]

Last Modified October 31, 1997
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies