Debian Codegraph @

doc/guide/src/MLBasisSyntaxAndSemantics.adoc

raw
1 = MLBasisSyntaxAndSemantics
2
3 An <<MLBasis#,ML Basis>> (MLB) file should have the `.mlb` suffix and
4 should contain a basis declaration.
5
6 == Syntax
7
8 A basis declaration (`_basdec_`) must be one of the following forms.
9
10 * `basis` `_basid_` `=` `_basexp_` (`and` `_basid_` `=` `_basexp_`)^{asterisk}^
11 * `open` `_basid~1~_` ... `_basid~n~_`
12 * `local` `_basdec_` `in` `_basdec_` `end`
13 * `_basdec_` [`;`] `_basdec_`
14 * `structure` `_strid_` [`=` `_strid_`] (`and` `_strid_`[`=` `_strid_`])^{asterisk}^
15 * `signature` `_sigid_` [`=` `_sigid_`] (`and` `_sigid_` [`=` `_sigid_`])^{asterisk}^
16 * `functor` `_funid_` [`=` `_funid_`] (`and` `_funid_` [`=` `_funid_`])^{asterisk}^
17 * `_path_.sml`, `_path_.sig`, or `_path_.fun`
18 * `_path_.mlb`
19 * `ann` `"_ann_"` `in` `_basdec_` `end`
20
21 A basis expression (`_basexp_`) must be of one the following forms.
22
23 * `bas` `_basdec_` `end`
24 * `_basid_`
25 * `let` `_basdec_` `in` `_basexp_` `end`
26
27 Nested SML-style comments (enclosed with `({asterisk}` and `*)`) are ignored
28 (but <<LineDirective#>>s are recognized).
29
30 Paths can be relative or absolute. Relative paths are relative to the
31 directory containing the MLB file. Paths may include path variables
32 and are expanded according to a <<MLBasisPathMap#,path map>>. Unquoted
33 paths may include alpha-numeric characters and the symbols `-` and
34 `_`, along with the arc separator `/` and extension separator
35 `.`. More complicated paths, including paths with spaces, may be
36 included by quoting the path with `"`. A quoted path is lexed as an
37 SML string constant.
38
39 <<MLBasisAnnotations#,Annotations>> allow a library author to
40 control options that affect the elaboration of SML source files.
41
42 == Semantics
43
44 There is a link:MLBasis.attachments/mlb-formal.pdf[formal semantics] for
45 ML Basis files in the style of the
46 <<DefinitionOfStandardML#,Definition>>. Here, we give an informal
47 explanation.
48
49 An SML structure is a collection of types, values, and other
50 structures. Similarly, a basis is a collection, but of more kinds of
51 objects: types, values, structures, fixities, signatures, functors,
52 and other bases.
53
54 A basis declaration denotes a basis. A structure, signature, or
55 functor declaration denotes a basis containing the corresponding
56 module. Sequencing of basis declarations merges bases, with later
57 definitions taking precedence over earlier ones, just like sequencing
58 of SML declarations. Local declarations provide name hiding, just
59 like SML local declarations. A reference to an SML source file causes
60 the file to be elaborated in the basis extant at the point of
61 reference. A reference to an MLB file causes the basis denoted by
62 that MLB file to be imported -- the basis at the point of reference
63 does _not_ affect the imported basis.
64
65 Basis expressions and basis identifiers allow binding a basis to a
66 name.
67
68 An MLB file is elaborated starting in an empty basis. Each MLB file
69 is elaborated and evaluated only once, with the result being cached.
70 Subsequent references use the cached value. Thus, any observable
71 effects due to evaluation are not duplicated if the MLB file is
72 referred to multiple times.