HELP STDTYPES R. J. Duncan, June 1989 The predefined types of PML. CONTENTS - (Use g to access required sections) -- The Structure StdTypes -- Primitive Types -- Datatypes -- Derived Types -- The Structure StdTypes --------------------------------------------- signature StdTypes structure StdTypes : StdTypes The structure -StdTypes- contains all the predefined type and value constructors of PML, with the exception of the stream types -instream- and -outstream- defined in structure -StdIO- (see HELP * STDIO). This set of types is identical to that required by the Standard ML language definition, Appendix C. The structure is open by default and the names it defines made "pervasive" so that they are visible everywhere. The -StdTypes- module is described by the following signature: signature StdTypes = sig (* Primitive Types *) eqtype int eqtype real eqtype string type exn (* Datatypes *) datatype bool = false | true datatype '_a ref = ref of '_a datatype 'a list = nil | op :: of 'a * 'a list (* Derived Types *) eqtype unit end; (* signature StdTypes *) -- Primitive Types ---------------------------------------------------- eqtype int The type of integer numbers. Integer numbers are constructed from basic integer constants, described in HELP * LEXICAL, and from the normal range of arithmetic operators defined in the structures -StdValues- and -Int- (see HELP * STDVALUES, * INT). Integers in PML have arbitrary precision: the only limit on the magnitude of an integer is the amount of memory available. eqtype real The type of real numbers. Real numbers are constructed from basic real constants, described in HELP * LEXICAL, and from the normal range of arithmetic operators defined in the structures -StdValues- and -Real- (see HELP * STDVALUES, * REAL). Real numbers in PML are implemented as double precision floating point: the exact details of range and precision will vary depending on the host machine. Some useful real constants are defined in structure -Real-. eqtype string The type of ASCII character strings. Strings are constructed from basic string constants, described in HELP * LEXICAL, and from a range of functions defined in structures -StdValues- and -String- (see HELP * STDVALUES, * STRING). Standard ML does not have a separate character type: single characters are represented by strings of length one. The functions -chr- and -ord- in structure -StdValues- define a mapping between ASCII codes and single- character strings. type exn The type of exceptions. Exceptions are used in ML for signalling and reacting to exceptional events using the syntactic forms -raise- and -handle- (see HELP * SYNTAX). Several primitive exceptions are defined in structure -StdValues- and elsewhere; new exceptions are created with the -exception- declaration form. -- Datatypes ---------------------------------------------------------- datatype bool con false con true The type of boolean values. The constructors -true- and -false- are the only values of this type. Special syntactic forms exist for the usual expression of conditional evaluation (-if-then-else-), boolean conjunction (-andalso-) and disjunction (-orelse-), as described in HELP * SYNTAX. datatype '_a ref con ref (x : '_a) The type of updatable references. The expression ref(x) (for any -x-) evaluates to a unique address with contents given by the value of -x-. Functions for accessing the contents at an address (!) and for updating the contents at an address (:=) are defined in structure -StdValues-. The imperative nature of references places restrictions on their types: this is indicated by the occurrence of the special type variable - '_a - in the summary above. Roughly speaking, such variables are not allowed to appear in the types of top-level expressions: in particular, all top-level references must have ground types. For a more precise description of these restrictions, refer to the SML language definition, section 4. datatype 'a list infixr 5 :: con nil con (x : 'a) :: (l : 'a list) The type of lists. Lists are constructed from the empty list -nil- and the infix constructor "::". Special syntax allows the expression e1 :: e2 :: ... :: en :: nil to be abbreviated [e1, e2, ..., en] In particular, -nil- alone can be abbreviated to "[]". A comprehensive range of list manipulation functions are defined in structures -StdValues- and -List- (see HELP * STDVALUES, * LIST). -- Derived Types ------------------------------------------------------ eqtype unit An abbreviation for the empty record type, defined: type unit = {} There is only one value of this type (hence its name): the empty record value, "{}", more commonly written as the empty tuple, "()". The unit type is used most often as the argument or result type of functions evaluated principally for their side-effects: for example, the function -output- defined in structure -StdIO- which writes a string to an output stream, returning no meaningful result, has type: output : outstream * string -> unit --- C.all/pml/help/stdtypes --- Copyright University of Sussex 1991. All rights reserved. ----------