basdec | ::= | basis basid = basexp (and basid = basexp)* |
| | open basid1 ··· basidn | |
| | local basdec in basdec end | |
| | basdec [;] basdec | |
| | structure strid [= strid] (and strid [= strid])* | |
| | signature sigid [= sigid] (and sigid [= sigid])* | |
| | functor funid [= funid] (and funid [= funid])* | |
| | path.sml | |
| | path.mlb | |
| | ann "ann" in basdec end | |
basexp | ::= | bas basdec end |
| | basid | |
| | let basdec in basexp end |
(* import libraries *) lib1.mlb ... libm.mlb (* program files *) file1.sml ... filen.smlThe bases denoted by lib1.mlb, ..., libm.mlb are merged (bindings of names in later bases take precedence over bindings of the same name in earlier bases), producing a basis in which file1.sml, ..., filen.sml are elaborated, possibly adding additional bindings to the basis.
local file1.sml ... filen.sml in (* export filter here *) functor F structure S endWhile file1.sml, ..., filen.sml may declare top-level identifiers in addition to F and S, such names are not accessible to programs and libraries that import this .mlb.
local file1.sml ... filen.sml in (* export filter, with renaming, here *) functor F structure S' = S endNote that functor F is an abbreviation for functor F = F, which simply exports an identifier under the same name.
local lib1.mlb in (* import filter here *) functor F end local lib2.mlb in (* import filter here *) structure S end file1.sml ... filen.sml
local lib1.mlb in (* import filter, with renaming, here *) structure S1 = S end local lib2.mlb in (* import filter, with renaming, here *) structure S2 = S end file1.sml ... filen.sml
signature EITHER_GLOBAL = sig datatype ('a, 'b) either = Left of 'a | Right of 'b val & : ('a -> 'c) * ('b -> 'c) -> ('a, 'b) either -> 'c val && : ('a -> 'c) * ('b -> 'd) -> ('a, 'b) either -> ('c, 'd) either end signature EITHER = sig include EITHER_GLOBAL val isLeft : ('a, 'b) either -> bool val isRight : ('a, 'b) either -> bool ... end
structure Either : EITHER = struct datatype ('a, 'b) either = Left of 'a | Right of 'b fun f & g = fn x => case x of Left z => f z | Right z => g z fun f && g = fn x => ((Left o f) & (Right o g)) x fun isLeft x = ((fn _ => true) & (fn _ => false)) x fun isRight x = (not o isLeft) x ... end structure EitherGlobal : EITHER_GLOBAL = Either
infixr 3 & &&
open EitherGlobal
local (* import Basis Library *) basis.mlb either-sigs.sml either-infixes.sml either-strs.sml in signature EITHER structure Either either-infixes.sml either-open.sml end
LIB_MLTON_DIR | /usr/lib/mlton |
MLTON_ROOT | $(LIB_MLTON_DIR)/sml |
$(MLTON_ROOT)/basis/basis.mlb |
The Standard ML Basis Library (see Section 9). |
$(MLTON_ROOT)/basis/basis-1997.mlb |
The (deprecated) 1997 specification of the Standard ML Basis Library. |
$(MLTON_ROOT)/basis/mlton.mlb |
The MLton structure and signatures (see Section 10.2). |
$(MLTON_ROOT)/basis/sml-nj.mlb |
The SMLofNJ structure and signature (see Section 10.3). |
$(MLTON_ROOT)/basis/unsafe.mlb |
The Unsafe structure and signature (see Section 10.4). |
$(MLTON_ROOT)/mlyacc-lib/mlyacc-lib.mlb |
Modules used by parsers built with mlyacc. |
$(MLTON_ROOT)/cml/cml.mlb |
Concurrent ML, a library for message-passing concurrency (see $(MLTON_ROOT)/cml/README). |
$(MLTON_ROOT)/basis/pervasive-types.mlb |
The top-level types and constructors of the Basis Library (see Section 9.1). |
$(MLTON_ROOT)/basis/pervasive-exns.mlb |
The top-level exception constructors of the Basis Library (see Section 9.2). |
$(MLTON_ROOT)/basis/pervasive-vals.mlb |
The top-level values of the Basis Library, without infix status (see Section 9.3). |
$(MLTON_ROOT)/basis/overloads.mlb |
The top-level overloaded values of the Basis Library, without infix status (see Section 9.4). |
$(MLTON_ROOT)/basis/equal.mlb |
The polymorphic equality = and inequality <> values, without infix status. |
$(MLTON_ROOT)/basis/infixes.mlb |
The infix declarations of the Basis Library. |
$(MLTON_ROOT)/basis/pervasive.mlb |
The entire top-level environment of the Basis Library, with infix status. |
basdec | ||
ann "ann" ("ann")+ in basdec end | ==> | ann "ann" in ann ("ann")+ in basdec end end |
local $(GEN_ROOT)/gen-lib.mlb ann "warnMatch false" in foo.gen.sml end in signature FOO structure Foo endStandard ML libraries can delivered via .mlb files. Authors of such libraries should strive to be mindful of the ways in which programmers may choose to compile their programs. For example, although the defaults for sequenceUnit and warnUnused are false, periodically compiling with these annotations defaulted to true can help uncover likely bugs. However, a programmer is unlikely to be interested in unused modules from an imported library, and the behavior of sequenceUnit true may be incompatible with some libraries. Hence, a library author may choose to deliver a library as follows:
ann "sequenceUnit false" "warnMatch true" "warnUnused true" "forceUsed" in local file1.sml ... filen.sml in functor F1 ... signature S1 ... structure SN ... end endThe annotations sequenceUnit true and warnMatch true have the obvious effect on elaboration. The annotations warnUnused true and forceUsed work in conjunction --- warning on any identifiers that do not contribute to the exported modules, and preventing warnings on exported modules that are not used in the remainder of the program. Many of the available libraries listed in Section 8.4 are delivered with these annotations.