/
mosmlref.tex
2014 lines (1589 loc) · 78.5 KB
/
mosmlref.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% mosmlref.tex v. 2.00.1 Copyright (C) Peter Sestoft 1994, 2000-08-02
%
% You may edit for lay-out, or leave out irrelevant sections (if
% such omissions are marked somehow), but you may not redistribute the
% sources. The authors' names and the Moscow ML URL must be left in place.
\documentclass[fleqn,a4paper]{article}
\def\allttcdots{\ensuremath{\cdots}}
% this is a hack to get the bullets to hyperlink to a comment: there must be a simpler way
\newcounter{extension}
\renewcommand{\theextension}{$\bullet$}
\newcommand{\x}[1][]{\ref{extension}{#1}}
%\newcommand{\x}[1][]{\ref{extension}{\bf{*}#1}}
\nonstopmode
\usepackage{alltt}
\usepackage{isolatin1,mosml,pslatex}
\usepackage[T1]{fontenc}
\usepackage{geometry}
% \documentstyle[A4,fleqn,notesart]{article}
\newcommand{\la}{$\langle$}
\newcommand{\ra}{$\rangle$}
\newcommand{\opop}{\la{\tt op}\ra}
\newcommand{\op}{{\tt op}}
\newcommand{\longmodid}{{\it longmodid}}
% True if running pdflatex
\newif\ifpdf
\ifx\pdfoutput\undefined
\pdffalse
\else
\pdftrue
\fi
% hyperref should be the *last* package loaded
\ifpdf
\pdfcompresslevel=9
% For interactive color output devices (i.e. computer displays):
\usepackage[pdfpagemode=None,colorlinks,urlcolor=blue]{hyperref}
\else
% For passive black and white output devices (i.e. printers):
\usepackage{hyperref}
\fi
\begin{document}
\begin{center}
\vspace*{0cm}
{\huge\bf Moscow ML Language Overview}\\[0.5cm]
{Version 2.00 of June 2000}\\[1cm]
Sergei Romanenko, Russian Academy of Sciences, Moscow, Russia\\
Claudio Russo, Cambridge University, Cambridge, United Kingdom\\
Peter Sestoft, Royal Veterinary and Agricultural University,
Copenhagen, Denmark
\end{center}
\noindent This is a compact reference to the language implemented by
Moscow ML, a superset of Standard ML\@. For reference material on
Standard ML, see Milner, Tofte, Harper and MacQueen: {\em The
Definition of Standard ML\/}, The MIT Press 1997. For a guide to
the practical use of Moscow ML, see the \emph{Moscow ML Owner's
Manual}. For a detailed description of all Moscow ML library
modules, see the \emph{Moscow ML Library Documentation}.
% {\bf Acknowledgements:} The present document owes a lot to the {\em
% Definition\/}.Thanks to Don Sannella at LFCS, Division of
% Informatics, University of Edinburgh for funding C. Russo under
% EPSRC grant GR/K63795 .
\tableofcontents
\vfill
\begin{center}
\begin{tabular}{|c|}\hline
\rule[-0.4cm]{0cm}{1cm}The Moscow ML home page is\ \
\url{http://www.dina.kvl.dk/~sestoft/mosml.html}\\\hline
\end{tabular}
\end{center}
\newpage
\section{Moscow ML's relation to Standard ML}\label{sec-SMLcompliance}
Moscow ML implements a proper extension of Standard ML,
as defined in the 1997 {\em Definition of Standard ML\/}.
This document describes the language implemented by Moscow ML, not Standard ML
\emph{per se}: users seeking an orthodox Standard ML reference should look elsewhere.
Having said that, Moscow ML is specifically designed to be backwards compatible with Standard ML. Thus every valid Standard ML program should be a valid
Moscow ML program, and Moscow ML may be used as if it were simply
a Standard ML compiler. Any deviation from this behaviour should be reported
as a bug.
% To facilitate the production of code that complies with Standard ML,
% both the batch compiler {\tt mosmlc} and the interactive system {\tt
% mosml} accept the command line options {\tt -orthodox}, {\tt
% -conservative} and {\tt -liberal}, which cause the compiler and
% interactive system to respectively reject, deprecate with a warning,
% or silently accept any Moscow ML specific extensions of Standard ML.
% The default compliance level is {\tt -conservative}. In the
% interactive system, the compliance level may be set interactively
% using the functions {\tt orthodox}, {\tt conservative} and {\tt
% liberal} of type {\tt unit -> unit}.
\section{Reserved words}
\label{sec-reserved-words}
% {\small\begin{verbatim}
% abstype and andalso as case do datatype else end exception fn fun
% handle if in infix infixr let local nonfix of op open orelse raise rec
% sig signature struct structure then type val with withtype while
% ( ) [ ] { } , : :> ; ... _ | = => -> #
% \end{verbatim}}
{\small\begin{alltt}
abstype and andalso as case do datatype else end eqtype exception fn fun functor
handle if in include infix infixr let local nonfix of op open orelse raise rec
sharing sig signature struct structure then type val where with withtype while
( ) [ ] \{ \} , : :> ; ... _ | = => -> #
\end{alltt}}
\section{Comments}
\label{sec-comments}
A comment is any character sequence within comment brackets \verb#(*#
and \verb#*)# in which comment brackets are properly nested.
\section{Special constants}
\label{sec-special-constants}
\subsubsection*{Integer constants}
\begin{quot}
\begin{tabular}{@{}lcllllllll}
Examples: & & \verb#0# & \verb#~0# & \verb#4# & \verb#~04# &
\verb#999999# & \verb#0xFFFF# & \verb#~0x1ff#\\
Non-examples: & & \verb#0.0# & \verb#~0.0# & \verb#4.0# & \verb#1E0# &
\verb#-317# & \verb#0XFFFF# & \verb#-0x1ff#\\
\end{tabular}
\end{quot}
\subsubsection*{Real constants}
\begin{quot}
\begin{tabular}{@{}lcllllllll}
Examples: & & \verb#0.7# & \verb#~0.7# & \verb#3.32E5# & \verb#3E~7#
& \verb#~3E~7# & \verb#3e~7# & \verb#~3e~7#\\
Non-examples: & & \verb#23# & \verb#.3# & \verb#4.E5# & \verb#1E2.0# &
\verb#1E+7# & \verb#1E-7#
\end{tabular}
\end{quot}
\subsubsection*{Word constants}
\begin{quot}
\begin{tabular}{@{}lcllllllll}
Examples: & & \verb#0w0# & \verb#0w4# & \verb#0w999999# &
\verb#0wxFFFF# & \verb#0wx1ff#\\
Non-examples: & & \verb#0w0.0# & \verb#~0w4# & \verb#-0w4# & \verb#0w1E0# &
\verb#0wXFFFF# & \verb#0WxFFFF#\\
\end{tabular}
\end{quot}
\subsubsection*{String constants}
A string constant is a sequence, between quotes (\verb#"#), of zero or
more printable characters, spaces, or escape sequences. An escape
sequence starts with the escape character \verb#\# and stands for a
character sequence:
\begin{quot}
\begin{tabular}{@{}lp{5in}}
\verb#\a# & A single character interpreted by the system as
alert (BEL, ASCII 7). \\
\verb#\b# & Backspace (BS, ASCII 8).\\
\verb#\t# & Horisontal tab (HT, ASCII 9).\\
\verb#\n# & Linefeed, also known as newline (LF, ASCII 10). \\
\verb#\v# & Vertical tab (VT, ASCII 11).\\
\verb#\f# & Form feed (FF, ASCII 12).\\
\verb#\r# & Carriage return (CR, ASCII 13).\\
\verb#\^#{\it c\/} & The control character {\it c\/}, where {\it
c\/} may be any character with ASCII code 64--95 (\verb#@# to
\verb#_#). The ASCII code of \verb#\^#{\it c\/} is 64 less than
that of {\it c\/}.\\
\verb#\#{\it ddd\/} & The character with code {\it ddd\/} (3 decimal
digits denoting an integer 0--255).\\
\verb#\u#{\it xxxx\/} & The character with code {\it xxxx\/} (4 hexadecimal
digits denoting an integer 0--255).\\
\verb#\"# & The double-quote character ({\tt "})\\
\verb#\\# & The backslash character (\verb#\#)\\
\verb#\#$f\cdot\cdot f$\verb#\# & This sequence is ignored, where
$f\cdot\cdot f$ stands for a sequence of one or more formatting
characters (such as space, tab, newline, form-feed).
\end{tabular}
\end{quot}
\subsubsection*{Character constants}
A character constant consists of the symbol \verb$#$ immediately
followed by a string constant of length one.
\begin{quot}
\begin{tabular}{@{}lclllll}
Examples: & & \verb$#"a" $ & \verb$#"\n" $ & \verb$#"\^Z" $ &
\verb$#"\255" $ & \verb$#"\""$\\
Non-examples: & & \verb$# "a"$ & \verb$#c$ & \verb$#"""$
\end{tabular}
\end{quot}
%\newpage
\section{Identifiers}
\label{sec-identifiers}
\begin{itemize}
\item {\bf alphanumeric:} a sequence of letters, digits, primes
(\verb#'#) and underbars (\verb#_#) starting with a letter or prime;
\item {\bf symbolic:} any non-empty sequence of the following symbols:\\
\verb; ! % & $ # + - / : < = > ? @ \ ~ ` ^ | *;
\end{itemize}
\noindent Reserved words (Section~\ref{sec-reserved-words}) are
excluded. This means that for example \verb$#$ and \verb#|# are not
identifiers, but \verb$##$ and \verb#|=|# are identifiers. There are
several classes of identifiers:
{\begin{center}
\begin{tabular}{@{}lll}
{\it vid } & (value identifiers) & long\\
{\it tyvar} & (type variables)\\
{\it tycon} & (type constructors) & long\\
{\it lab} & (record labels)\\
{\it strid} & (structure identifiers) & long\\
{\it funid} & (functor identifiers) & long\\
{\it modid} & (module identifiers) & long\\
{\it sigid} & (signature identifiers)\\
{\it unitid} & (unit identifiers)
\end{tabular}
\end{center}}
\begin{itemize}
\item A type variable \verb#'a# is an alphanumeric identifier starting
with a prime.
%\item An equality type variable \verb#''a# starts with two or more primes.
%
%\item An imperative type variable \verb#'_a# starts with one or two primes
% followed by an underbar.
%
%\item An applicative type variable is one which is not imperative.
\item A label lab is an identifier, or a positive integral numeral
\verb#1 2 3 #\ldots\ not starting with \verb#0#.
\item For each identifier class X marked `long' above there is a class
longX of long identifiers, which may have a qualifier consisting of
a long structure identifier followed by a dot `\texttt{.}' :
\begin{center}
\begin{tabular}{llll}
{\it longx\/} & ::= & {\it x\/} & identifier\\
& & {\it longstrid\/}\texttt{.}{\it x\/} & qualified identifier
\end{tabular}
\end{center}
\item
Although structure and functor identifiers reside in separate name-spaces,
the syntax of structure and functor identifiers is identical. The
set of identifiers
{\it modid} ranges over the union of {\it strid} and {\it funid};
{\it longmodid} ranges over the union of {\it longstrid} and {\it longfunid}.
Moscow ML uses type information to resolve each occurrence of a
{\it modid} or {\it longmodid}
to a structure or functor identifier during type checking, using
the optional keyword \op\ to resolve any remaining ambiguities.
See the comments at the end of Section \ref{sec-modules}.
\item Any occurrence of a structure identifier {\it strid\/} that is
not bound in the current context refers to the unit implementation
{\tt unitid.uo\/} of the same name (ie. {\tt unitid} = {\it strid}).
At compile time, the unit's compiled interface {\tt unitid.ui\/}
must exist and have been compiled in \emph{structure} mode. At link
time, the unit's compiled implementation {\tt unitid.uo\/} must
exist and have been compiled in \emph{structure} mode.
\item Any occurrence of a signature identifier {\it sigid\/} that is not
bound in the current context refers to the compiled unit interface
{\tt unitid.ui\/} of the same name (ie. {\tt unitid} = {\it sigid}).
The file {\tt unitid.ui\/} must have been compiled in \emph{structure}
mode from an explicit interface {\tt unitid.sig}.
\end{itemize}
\newpage
\section{Infixed operators}
\label{sec-infixed-operators}
An identifier may be given infix status by the {\tt infix} or {\tt
infixr} directive, which may occur as a declaration or specification. If identifier
{\it id\/} has infix status, then {\it exp\/}$_1$ {\it id\/} {\it
exp\/}$_2$ may occur, in parentheses if necessary, wherever the
application {\it id\/}\verb#(#{\it exp\/}\et\verb#,# {\it
exp\/}\to\verb#)# or {\it id\/}\verb#{1=#{\it
exp\/}\et\verb#,2=#{\it exp\/}\to\verb#}# would otherwise occur.
Infix identifiers in patterns are analogous. On the other hand, an
occurrence of a qualified identifier, or any identifier prefixed by
{\tt op}, is treated as non-infixed. The form of the fixity directives
is as follows ($n\geq 1$):
\begin{center}
\begin{tabular}{@{}llll}
{\tt infix} & $\langle d\rangle$ & $id_1 \cdots id_n$ & left associative\\
{\tt infixr} & $\langle d\rangle$ & $id_1 \cdots id_n$ & right associative\\
{\tt nonfix} & & $id_1 \cdots id_n$ & non-associative
\end{tabular}
\end{center}
\noindent where $\langle d\rangle$ is an optional decimal digit $d$
indicating binding precedence. A higher value of $d$ indicates
tighter binding; the default is \verb#0#. Fixity directives are
subject to the usual scope rules governing visibility of identifiers
declared inside {\tt let} and {\tt local}.
Fixity directives occurring within {\it dec} in a structure expression
{\tt struct {\it dec\/} end} are local to {\it dec}.
Fixity directives occurring within {\it spec} in a signature
{\tt sig {\it spec\/} end} are local to {\it spec}.
Mixed left-associative operators of the same precedence associate to
the left, mixed right-associative operators of the same precedence
associate to the right, and it is illegal to mix left- and
right-associative operators of the same precedence.
\section{Notational conventions used in the grammar}
\begin{itemize}
\item Each syntax class is defined by a list of alternatives, one
alternative on each line. An empty phrase is represented by an
empty line.
\item The brackets \la\ and \ra\ enclose optional phrases.
%\newpage
\item For any syntax class X (over which {\it x\/} ranges) we define the syntax
class Xseq (over which {\it xseq\/} ranges) as follows:
\begin{center}
\begin{tabular}{llll}
{\it xseq\/} & ::= & {\it x\/} & (singleton sequence)\\
& & & (empty sequence)\\
& & {\tt ($x_1$, $\cdots$ , $x_n$)} & (sequence,
$n\geq 1$)
\end{tabular}
\end{center}
\item Alternative phrases are listed in order of decreasing precedence.
\item L and R indicate left and right association.
\item The syntax of types binds more tightly than that of expressions.
\item Each iterated construct (e.g.\ {\it match\/}) extends as far to
the right as possible. Hence a {\tt case} inside a {\tt case}, {\tt
fn}, or {\tt fun} may have to be enclosed in parentheses.
\item Moscow ML phrases that are non-compliant
extensions of Standard ML syntax are
marked with an bullet (\x) in the margin.
\item Moscow ML phrases that are non-compliant generalisations of
Standard ML syntax, but have instances that comply with Standard
ML, are marked with an an bullet and a number (\x[$N$]) in the
margin, where $N$ refers to an explanatory comment that appears
in Section \ref{sec-SMLrestrictions}.
\end{itemize}
\newpage
\section{Grammar for the Moscow ML Core language}
\label{sec-grammar-core}
\subsubsection*{Expressions and Matches}
\begin{tabular}{@{}lllll}
{\it exp\/} & ::= & {\it infexp\/}\\
& & {\tt {\it exp\/} :\ {\it ty\/}} & type constraint (L)\\
& & {\tt {\it exp\/}\et\ andalso {\it exp\/}\to} & sequential conjunction\\
& & {\tt {\it exp\/}\et\ orelse {\it exp\/}\to} & sequential disjunction\\
& & {\tt {\it exp\/} handle {\it match\/}} & handle exception\\
& & {\tt raise {\it exp\/}} & raise exception\\
& & {\tt if {\it exp\/}\et\ then {\it exp\/}\to\ else {\it exp\/}\tre}
& conditional\\
& & {\tt while {\it exp\/}\et\ do {\it exp\/}\to} & iteration\\
& & {\tt case {\it exp\/} of {\it match\/}} & case analysis\\
& & {\tt fn {\it match\/}} & function expression\\[2ex]
{\it infexp\/} & ::= & {\it appexp\/}\\
& & {\it infexp\/}\et\ {\it id\/} {\it infexp\/}\to & infixed
application\\[2ex]
{\it appexp\/} & ::= & {\it atexp\/}\\
& & {\it appexp\/} {\it atexp\/} & application\\[2ex]
{\it atexp\/} & ::= & {\it scon\/} & special constant
(see Section~\ref{sec-special-constants})\\
& & \la{\tt op}\ra\ {\it longvid\/} & value identifier\\
& & \verb#{# \la\ {\it exprow\/} \ra\ \verb#}# & record\\
& & \verb$#$ {\it lab\/} & record selector\\
& & \verb#()# & 0-tuple\\
& & {\tt ({\it exp\/}\et, $\cdots$ , {\it exp\/}\n)}
& $n$-tuple, $n\geq 2$\\
& & {\tt [{\it exp\/}\et, $\cdots$ , {\it exp\/}\n]}
& list, $n\geq 0$\\
& & {\tt \#[{\it exp\/}\et, $\cdots$ , {\it exp\/}\n]}
& vector, $n\geq 0$\\
& & {\tt ({\it exp\/}\et; $\cdots$ ; {\it exp\/}\n)}
& sequence, $n\geq 2$\\
& & {\tt let {\it dec\/} in {\it exp\/}\et; $\cdots$ ; {\it exp\/}\n\
end} & local declaration, $n\geq 1$\\
& & {\tt [ structure {\it modexp\/} as {\it sigexp\/} ]} & structure package & \x \\
& & {\tt [ functor {\it modexp\/} as {\it sigexp\/} ]} & functor package & \x \\
& & {\tt ( {\it exp\/} ) }\\[2ex]
{\it exprow\/} & ::= & {\tt {\it lab\/} = {\it exp\/} \la\ , {\it
exprow\/} \ra} & expression row\\[2ex]
{\it match\/} & ::= & {\tt {\it mrule\/} \la\ | {\it match\/} \ra}\\[2ex]
{\it mrule\/} & ::= & {\tt {\it pat\/} => {\it exp\/}}
\end{tabular}
\subsubsection*{Declarations and Bindings}
\begin{tabular}{@{}lllll}
{\it dec\/} & ::= & {\tt val {\it tyvarseq\/} {\it valbind\/}} & value declaration\\
& & {\tt fun {\it tyvarseq\/} {\it fvalbind\/}} & function declaration\\
& & {\tt type {\it typbind\/}} & type declaration\\
& & {\tt datatype {\it datbind\/} \la\ withtype {\it typbind\/} \ra}
& datatype declaration\\
& & {\tt datatype {\it tycon\/} = datatype {\it tyconpath\/}}
& datatype replication\\
& & {\tt abstype {\it datbind\/} \la\ withtype {\it typbind\/} \ra}
& abstype declaration\\
& & \hspace{1.5cm}{\tt with {\it dec\/} end}\\
& & {\tt exception {\it exbind\/}} & exception declaration\\
& & {\tt local {\it dec\/}\et\ in {\it dec\/}\to\ end}
& local declaration\\
& & {\tt open {\it longstrid\/}\et\ $\cdots$ {\it longstrid\/}\n}
& open declaration, $n\geq 1$\\
& & {\tt structure {\it strbind}}
& structure declaration & \x[\ref{strdec}]\\
& & {\tt functor {\it funbind}}
& functor declaration & \x[\ref{topdec}]\\
& & {\tt signature {\it sigbind}}
& signature declaration & \x[\ref{topdec}]\\
& & & empty declaration\\
& & {\tt {\it dec\/}\et\ \la;\ra\ {\it dec\/}\to}
& sequential declaration\\
& & {\tt infix \la{\it d\/}\ra\ $id_1 \cdots id_n$} & infix (left)
directive, $n\geq 1$\\
& & {\tt infixr \la{\it d\/}\ra\ $id_1 \cdots id_n$} & infix (right)
directive, $n\geq 1$\\
& & {\tt nonfix $id_1 \cdots id_n$} & nonfix directive, $n\geq
1$\\[2ex]
{\it valbind\/} & ::= & {\tt {\it pat\/} = {\it exp\/} \la\ and {\it
valbind\/} \ra} & value binding\\
& & {\tt rec {\it valbind\/}} & recursive binding\\[2ex]
{\it fvalbind\/} & ::= &
\begin{tabular}[t]{ll}
{\tt \ \ \opop\ {\it var\/} {\it atpat\/}\et\et\ $\cdots$ {\it atpat\/}\et\n\
\la{:}ty\ra\ = {\it exp\/}\et}\\
{\tt | \opop\ {\it var\/} {\it atpat\/}\to\et\ $\cdots$ {\it atpat\/}\to\n\
\la{:}ty\ra\ = {\it exp\/}\to}\\
{\tt | $\cdots$}\\
{\tt | \opop\ {\it var\/} {\it atpat\/}\m\et\ $\cdots$ {\it atpat\/}\m\n\
\la{:}ty\ra\ = {\it exp\/}\m}\\
{\tt \ \ \ \la\ and {\it fvalbind\/} \ra}
\end{tabular} & $m,n\geq 1$\\[12ex]
{\it typbind\/} & ::= & {\tt {\it tyvarseq\/} {\it tycon\/} = {\it
ty\/} \la\ and {\it typbind\/} \ra} & \x[\ref{closure}]\\[2ex]
{\it datbind\/} & ::= & {\tt {\it tyvarseq\/} {\it tycon\/} = {\it
conbind\/} \la\ and {\it datbind\/} \ra} & \x[\ref{closure}]\\[2ex]
{\it conbind\/} & ::= & {\tt \opop\ {\it vid\/} \la{of} {\it ty\/}\ra\ \la\ | {\it conbind\/} \ra}\\[2ex]
{\it exbind\/} & ::= & {\tt \opop\ {\it vid\/} \la{of}
{\it ty\/}\ra\ \la\ and {\it exbind\/} \ra}\\
& & {\tt \opop\ {\it vid\/} = \opop\ {\it longvid\/} \la\ and {\it
exbind\/} \ra}\\[2ex]
\end{tabular}
\noindent Note: In the {\it fvalbind\/} form above, if {\it var\/} has
infix status then either {\tt op} must be present, or {\it var\/} must
be infixed. Thus, at the start of any clause, {\tt op {\it var\/}
({\it atpat\/}, {\it atpat\/}$'$)} may be written {\tt ({\it
atpat\/} {\it var\/} {\it atpat\/}$'$)}. The parentheses may be
dropped if `{\tt :{\it ty\/}}' or `{\tt =}' follows immediately.
\subsubsection*{Type expressions}
\begin{tabular}{@{}lllll}
{\it tyconpath\/} & ::= & {\it longtycon\/} & long type constructor\\
& & {\tt {\it longtycon\/} where {\it strid\/} = {\it modexp\/}}& type constructor projection &\x\\[2ex]
{\it ty\/} & ::= & {\it tyvar\/} & type variable\\
& & {\tt \{ \la\ {\it tyrow\/} \ra\ \}} & record type expression\\
& & {\tt {\it tyseq\/} {\it tyconpath\/}} & type construction & \\
& & {\tt {\it ty\/}\et\ * $\cdots$ * {\it ty\/}\n} & tuple type,
$n\geq 2$\\
& & {\tt {\it ty\/}\et\ -> {\it ty\/}\to} & function type expression\\
& & {\tt [ {\it sigexp} ]} & package type expression & \x\\
& & {\tt ( {\it ty\/} )}\\[2ex]
{\it tyrow\/} & ::= & {\tt {\it lab\/} :\ {\it ty\/} \la\ , {\it
tyrow\/} \ra} & type-expression row
\end{tabular}
\subsubsection*{Patterns}
\begin{tabular}{@{}llll}
{\it atpat\/} & ::= & \verb#_# & wildcard\\
& & {\it scon\/} & special constant (see Section~\ref{sec-special-constants})\\
& & {\tt \opop\ {\it longvid\/}} & value identifier\\
& & {\tt \{ \la\ {\it patrow\/} \ra\ \}} & record\\
& & {\tt ()} & 0-tuple\\
& & {\tt ({\it pat\/}\et, $\cdots$ , {\it pat\/}\n)} & $n$-tuple,
$n\geq 2$\\
& & {\tt [{\it pat\/}\et, $\cdots$ , {\it pat\/}\n]} & list, $n\geq 0$\\
& & {\tt \#[{\it pat\/}\et, $\cdots$ , {\it pat\/}\n]} & vector, $n\geq 0$\\
& & {\tt ( {\it pat\/} )}\\[2ex]
{\it patrow\/} & ::= & {\tt ...} & wildcard\\
& & {\tt {\it lab\/} = {\it pat\/} \la\ , {\it patrow\/} \ra} &
pattern row\\
& & {\tt {\it lab\/} \la{:}{\it ty\/}\ra\ \la\ as {\it pat\/} \ra\
\la\ , {\it patrow\/} \ra} & label as variable\\[2ex]
{\it pat\/} & ::= & {\it atpat\/} & atomic pattern\\
& & {\tt \opop\ {\it longvid\/} {\it atpat\/}} & constructed value\\
& & {\tt {\it pat\/}\et\ {\it vid\/} {\it pat\/}\to} &
infixed value construction\\
& & {\tt {\it pat\/} :\ {\it ty\/}} & typed\\
& & {\tt \opop\ {\it var\/} \la{:}{\it ty\/}\ra\ as {\it pat\/}} & layered
\end{tabular}
\subsubsection*{Syntactic restrictions}
\begin{itemize}
\item No pattern may bind the same {\it var\/} twice. No expression
row, pattern row or type row may bind the same {\it lab\/} twice.
\item No binding {\it valbind\/}, {\it typbind\/}, {\it datbind\/} or
{\it exbind\/} may bind the same identifier twice; this applies also
to value constructors within a {\it datbind\/}.
\item In the left side {\it tyvarseq tycon\/} of any {\it typbind\/}
or {\it datbind\/}, {\it tyvarseq\/} must not contain the same {\it
tyvar\/} twice.
Moscow ML
requires that any {\it tyvar\/} occurring within the right side
is in scope (either explictly or implicitly), but not necessarily in
{\it tyvarseq} (cf. Section \ref{sec-SMLrestrictions}, restriction \ref{closure}).
\item For each value binding {\tt {\it pat\/} = {\it exp\/}} within
{\tt rec}, {\it exp\/} must be of the form {\tt fn {\it match\/}},
possibly enclosed in parentheses, and possibly constrained by one or
more type expressions.
\item No {\it valbind}, {\it datbind}, or {\it exbind} may bind {\tt
true}, {\tt false}, {\tt nil}, {\tt ::}, or {\tt ref}. No {\it
datbind} or {\it exbind} may bind {\tt it}.
\end{itemize}
\section{Interactive sessions}
An expression {\it exp\/} which occurs grammatically at top-level in
an interactive session is taken to be an abbreviation for the
declaration
\begin{quot}
{\tt val it = {\it exp\/}}
\end{quot}
\noindent This convention applies to interactive sessions only. In a
batch-compiled unit, write {\tt val it = {\tt exp}}\\ or {\tt val \verb#_# =
{\it exp\/}} etc.
\newpage
\section{Grammar for the Moscow ML Modules language}
\label{sec-modules}
The Moscow ML Modules language is a superset of the full Standard ML Modules language.
\subsubsection*{Module expressions}
\begin{tabular}{@{}lllll}
{\it modexp\/} & ::= & {\it appmodexp\/}\\
& & {\tt {\it modexp\/} :\ {\it sigexp\/}} & transparent constraint (L)\\
& & {\tt {\it modexp\/} :> {\it sigexp\/}} & opaque constraint (L)\\
& & {\tt functor ( {\it modid\/} :\ {\it sigexp} ) => {\it modexp}} & generative functor & \x \\
& & {\tt functor {\it modid\/} :\ {\it sigexp\/} => {\it modexp}} & applicative functor & \x \\
& & {\tt rec ( {\it strid\/} :\ {\it sigexp} ) {\it modexp}} & recursive structure& \x \\[2ex]
{\it appmodexp\/} & ::= & {\it atmodexp\/}\\
& & {\tt {\it appmodexp\/} {\it atmodexp\/}} & functor application&\x[\ref{atmodexp}] \\[2ex]
{\it atmodexp\/} & ::= & {\tt struct {\it dec\/} end} & basic\\
& & {\tt \opop\ {\it longmodid\/}}& module identifier\\
& & {\tt let {\it dec\/} in {\it modexp\/} end} & local declaration\\
& & {\tt ( {\it dec \/} )} & abbreviated structure & \x \\
& & {\tt ( {\it modexp\/} )} \\
\end{tabular}
\subsubsection*{Module bindings}
\begin{tabular}{@{}lllll}
{\it strbind\/} & ::= & {\tt {\it strid\/} \la\ {\it con} \ra\ = {\it modexp} \la\ and {\it strbind} \ra}
& structure binding\\
& & {\tt {\it strid\/} as {\it sigexp} = {\it exp} \la\ and {\it strbind} \ra}
& package binding & \x \\[2ex]
%{\it funbind\/} & ::= & {\tt {\it funid\/} = {\it modexp} \la\ and {\it funbind} \ra}
{\it funbind\/} & ::= & {\tt {\it funid\/} {\it arg}\et\ $\cdots$\ {\it arg}\n\ \la\ {\it con\/} \ra\ = {\it modexp}} & \\
& & \quad {\tt \la\ and {\it funbind} \ra} & functor binding, $n \geq 0$ & \x[\ref{funbind}]\\
& & {\tt {\it funid\/} ( {\it spec} ) \la\ {\it con\/} \ra\ = {\it modexp}} & \\
& & \quad {\tt \la\ and {\it funbind} \ra} & abbreviated generative binding\\
& & {\tt {\it funid\/} as {\it sigexp} = {\it exp} \la\ and {\it funbind} \ra}
& package binding & \x\\[2ex]
{\it sigbind\/} & ::= & {\tt {\it sigid\/} = {\it sigexp} \la\ and {\it sigbind} \ra}
& signature binding\\[2ex]
{\it con\/} & ::= & {\tt :} {\it sigexp} & transparent constraint \\
& & {\tt :>} {\it sigexp} & opaque constraint \\
{\it arg\/} & ::= & {\tt ( {\it modid\/} :\ {\it sigexp} )} & argument of generative functor \\
& & {\tt {\it modid\/} :\ {\it sigexp} } & argument of applicative functor & \x \\\
\end{tabular}
\subsubsection*{Signature expressions}
\begin{tabular}{@{}lllll}
{\it sigexp\/} & ::= & {\tt sig {\it spec\/} end}& basic\\
& & {\tt {\it sigid\/}} & signature identifier \\
%& & {\tt {\it sigexp\/} where type {\it tyvarseq\/} {\it longtycon} = {\it ty}} & type realisation & \x[\ref{closure}]\\
& & {\tt {\it sigexp\/} where {\it typreal\/}}& type realisation \\
& & {\tt functor ( {\it modid\/} :\ {\it sigexp} ) -> {\it sigexp}} & opaque functor signature & \x \\
& & {\tt functor {\it modid\/} :\ {\it sigexp\/} -> {\it sigexp}} & transparent functor signature & \x \\
& & {\tt rec ( {\it strid\/} :\ {\it sigexp} ) {\it sigexp}} & recursive structure signature & \x \\[2ex]
{\it typreal\/} & ::= & {\tt type {\it tyvarseq\/} {\it longtycon\/} = {\it ty\/}
\la\ and {\it typreal\/} \ra} & type realisation & \x[\ref{closure}]
\end{tabular}
\subsubsection*{Specifications and Descriptions}
\begin{tabular}{lllll}
{\it spec} & ::= & {\tt val} {\it tyvarseq} {\it valdesc} & value specification & \x[\ref{valspec}] \\
%& & {\tt val} {\it valdesc} & value specification &
& & {\tt type} {\it typdesc} & abstract type \\
& & {\tt type} {\it typbind} & type abbreviation \\
& & {\tt eqtype} {\it typdesc} & abstract equality type\\
%& & {\tt datatype} {\it datdesc} & datatype\\
& & {\tt datatype} {\it datdesc} \la\ {\tt withtype} {\it typbind\/} \ra\ &
datatype with typbind & \x[\ref{datatypespec}]\\
& & {\tt datatype {\it tycon\/} = datatype {\it tyconpath\/}}
& datatype replication\\
& & {\tt exception} {\it exdesc} & exception\\
& & {\tt structure} {\it strdesc} & structure\\
& & {\tt functor} {\it fundesc} & functor & \x \\
& & {\tt signature} {\it sigbind} & signature & \x \\
& & {\tt include} {\it sigid\/}\et\ $\cdots$\ {\it strid\/}\n & include,
$n \geq 1$ \\
& & {\tt local} {\it lspec} {\tt in} {\it spec} {\tt end}
& local specifications & \x\\
& & & empty\\
& & {\tt {\it spec} $\langle${;}$\rangle$ {\it spec}} & sequential\\
%& & {\tt {\it spec} sharing type {\it longtycon}\et\ =\ $\cdots$\ =\ {\it longtycon}\n} & type sharing, $n \geq 2$\\
& & {\tt {\it spec} sharing type }& type sharing, $n \geq 2$\\
& & {\tt \quad {\it longtycon}\et\ =\ $\cdots$\ =\ {\it longtycon}\n} \\
%& & {\tt {\it spec} sharing {\it longstrid}\et =\ $\cdots$\ = {\it longstrid}\n} & structure sharing, $n \geq 2$\\
& & {\tt {\it spec} sharing} & structure sharing, $n \geq 2$\\
& & {\tt \quad {\it longstrid}\et\ =\ $\cdots$\ =\ {\it longstrid}\n} \\
& & {\tt infix \la{\it d\/}\ra\ $id_1 \cdots\ id_n$} & infix (left)
directive, $n\geq 1$ & \x \\
& & {\tt infixr \la{\it d\/}\ra\ $id_1 \cdots\ id_n$} & infix (right)
directive, $n\geq 1$ & \x \\
& & {\tt nonfix $id_1 \cdots id_n$} & nonfix directive, $n\geq 1$ & \x \\[2ex]
{\it lspec} & ::= & {\tt open} {\it longstrid$_1$\/} $\cdots$\ {\it
longstrid$_n$\/}
& (local) open & \x \\
& & {\tt type} {\it typbind} & type abbreviation & \x \\
& & {\tt local} {\it lspec\/} {\tt in} {\it lspec} {\tt end}
& local specifications & \\
& & & empty & \x \\
& & {\tt {\it lspec\/} $\langle${;}$\rangle$ {\it lspec\/}} & sequential& \x\\[2ex]
{\it valdesc\/} & ::= & {\tt {\it vid\/} :\ {\it ty\/} \la\ and {\it
valdesc\/} \ra} & value description\\[2ex]
{\it typdesc\/} & ::= & {\tt {\it tyvarseq\/} {\it tycon\/} \la\ and
{\it typdesc\/} \ra} & type constructor description\\[2ex]
{\it datdesc\/} & ::= & {\tt {\it tyvarseq\/} {\it tycon\/} = {\it
condesc\/} \la\ and {\it datdesc\/} \ra} & datatype description & \x[\ref{closure}] \\[2ex]
{\it condesc\/} & ::= & {\tt {\it vid\/} \la{of} {\it ty\/}\ra\
\la\ | {\it condesc\/} \ra} & constructor description\\[2ex]
{\it exdesc\/} & ::= & {\tt {\it vid\/} \la{of} {\it ty\/}\ra\ \la\
and {\it exdesc\/} \ra} & exception constructor description\\[2ex]
{\it strdesc\/} & ::= & {\tt {\it strid\/} :\ {\it sigexp\/}
\la\ and {\it strdesc\/} \ra} & structure description\\[2ex]
{\it fundesc\/} & ::= & {\tt {\it funid\/} :\ {\it sigexp\/}
\la\ and {\it fundesc\/} \ra} & functor description\\[2ex]
\end{tabular}
\begin{itemize}
\item Although structure and functor identifiers reside in separate name-spaces,
the syntax of structure and functor identifiers is identical.
In the grammar, a module identifier {\it longmodid} may stand for either a
structure identifier {\it longstrid} or a functor identifier {\it longfunid}.
Thus, {\sl a priori}, the module expression \opop\ \longmodid\
may refer to a either a functor or a structure and the compiler
must resolve this ambiguity (\opop\ is an optional prefix of the keyword \op).
Fortunately,
the context of the phrase often rules out one
alternative, on the grounds that choosing that alternative
would force type checking to fail. In particular,
if \opop\ \longmodid\ occurs as the right hand side of a structure
(functor) binding, then \longmodid\ must be interpreted as a
structure (functor) identifier; if
\opop\ \longmodid\ occurs in the functor position of an application, then
\longmodid\ must be interpreted as a functor identifier; if
\opop\ \longmodid\ is constrained by a signature
then the signature
forces a unique interpretation
on \longmodid\ (depending on whether the signature specifies a structure or functor).
Similarly, if \opop\ \longmodid\ occurs as the argument of a functor application,
then the functor's domain forces a unique interpretation
on \longmodid.
Indeed, the only ambiguity that remains occurs when \opop\ \longmodid\ is the body of a functor. In this case, the optional prefix \opop\ is used to resolve
the ambiguity: the {\sl absence} of \op\ signals
that \longmodid\ refers to structure; the {\sl presence} of \op\ signals that
\op~\longmodid\ refers to a functor.
When the interpretation of \opop\ \longmodid\ is already
determined by the context, the optional prefix \opop\ has {\sl no} effect.
(This method of disambiguation relies on type information and is performed during
type checking.)
\item In a functor or functor signature's formal argument,
{\tt ( {\it modid\/} :\ {\it sigexp} )} or
{\tt {\it modid\/} :\ {\it sigexp} },
if {\it sigexp}
specifies a structure then {\it modid} binds the equivalent
structure identifier {\it strid};
if {\it sigexp} specifies a functor, then {\it modid}
binds the equivalent functor identifier {\it funid}.
\item In a structure expression {\tt struct {\it dec\/} end}, any
signature declared in {\it dec\/} is local to {\it dec\/}: it does not
define a component of the structure {\tt struct {\it dec\/} end}, nor
is it visible in the type of {\tt struct {\it dec\/} end}.
(Note that the syntax for signature identifiers is not long, in
the sense of Section \ref{sec-identifiers}.)
\item In a signature expression {\tt sig {\it spec\/} end}, any
signature declared in {\it spec\/} is local to {\it spec\/}: in particular,
such a declaration does \emph{not}
specify that a structure matching {\tt sig {\it spec\/} end} should
also declare that signature.
\end{itemize}
\subsubsection*{Syntactic restrictions}
\begin{itemize}
\item No binding {\it strbind\/}, {\it funbind\/}, or {\it sigbind \/} may bind
the same identifier twice.
\item No specification {\it valdesc\/}, {\it typdesc\/}, {\it
typbind\/}, {\it datdesc\/}, {\it exdesc\/}, {\it strdesc} or {\it fundesc} may describe the same identifier twice; this applies also to value constructors
within a {\it datdesc\/}.
\item In the left side {\it tyvarseq tycon\/} in any {\it typdesc\/},
{\it typbind\/}, {\it datdesc\/}, or {\it typreal},
or specification {\tt val {\it tyvarseq valdesc}}, {\it tyvarseq\/} must not
contain the same {\it tyvar\/} twice.
Moscow ML
requires that any {\it tyvar\/} occurring within the right side
is in scope (either explictly or implicitly), but not necessarily in
{\it tyvarseq} (cf. Section \ref{sec-SMLrestrictions}, restriction \ref{closure}).
\item No sequential specification
may specify the same {\it tycon}, {\it vid}, {\it strid}, {\it funid}, {\it sigid} or {\it id} (in a fixity specification) twice.
\item No {\it valdesc}, {\it datdesc}, or {\it exdesc} may specify
{\tt true}, {\tt false}, {\tt nil}, {\tt ::}, or {\tt ref}. No {\it
datdesc\/} or {\it exdesc} may specify {\tt it}.
\item In a generative functor {\tt functor ( {\it modid\/} :\ {\it sigexp} ) => {\it modexp}}
or applicative functor {\tt functor {\it modid\/} :\ {\it sigexp\/} => {\it modexp}}
the body of {\it modexp} must be {\it applicative} in the sense that it contains
no structure or functor bindings of the form
{\tt {\it strid\/} as {\it sigexp} = {\it exp}} or
{\tt {\it funid\/} as {\it sigexp} = {\it exp}},
excluding those bindings that occur within a Core {\tt let}-expression.
This restriction also applies to the bodies of functors declared in a {\it funbind}.
\end{itemize}
\newpage
\section{Grammar for the Moscow ML Unit language}
Moscow ML supports the separate compilation of named program fragments
called \emph{units}. A unit {\tt unitid} consists of an optional
\emph{unit interface} in file {\tt unitid.sig}. Each unit can be
compiled in one of two \emph{modes}: \emph{structure} mode and
\emph{toplevel} mode. A unit's implementation and interface files
must be compiled in the \emph{same} mode.
In the batch compiler {\tt mosmlc}, a unit's compilation mode is
specified by preceding it with the command-line argument {\tt -structure}
(the default) or {\tt -toplevel}. In the interactive
system {\tt mosml}, the compilation mode of a unit is determined by
the function with which it is compiled: {\tt compile} and
{\tt compileStructure} compile in \emph{structure} mode;
{\tt compileToplevel} compiles in \emph{toplevel} mode.
Note that the intended mode of a unit is not determined by file name
extension or by file content: the mode must be explicitly indicated
to the batch compiler and interactive system.
The syntax and semantics of a unit's interface and implementation
files depends on the mode and is described in the following sections.
\subsection{Syntax and semantics for units compiled in \emph{structure} mode}
In \emph{structure} mode, the unit interface file {\tt unitid.sig}, if
present, must contain a single Moscow ML signature declaration binding
the signature {\tt unitid}; the unit implementation file {\tt
unitid.sml} must contain a single Moscow ML structure declaration,
binding the structure {\tt unitid}. The unit interface may be
omitted.
With the batch compiler {\tt mosmlc}, the files {\tt unitid.sig} and
{\tt unitid.sml} are compiled in \emph{structure} mode if their
filenames are preceded by the command line argument {\tt -structure},
eg:
\begin{alltt}
mosmlc -c -structure unitid.sig unitid.sml
\end{alltt}
\noindent Since \emph{structure} mode is the default compilation
mode, the {\tt -structure} option may also be omitted:
\begin{alltt}
mosmlc -c unitid.sig unitid.sml
\end{alltt}
\noindent
In the interactive system, a unit interface or implementation may be
compiled in structure mode using the functions {\tt compile} and {\tt
compileStructure}.
The semantics of
\begin{alltt}
- compileStructure ["unitid\et",\allttcdots,"unitid\n"] "unitid.sig";(* if unitid.sig exists *)
- compileStructure ["unitid\et",\allttcdots,"unitid\n"] "unitid.sml";
- load "unitid";
\end{alltt}
\noindent is roughly equivalent to that of
\begin{alltt}
- load "unitid\et";
\allttcdots
- load "unitid\n";
- use "unitid.sig"; (* if unitid.sig exists *)
- use "unitid.sml";
\end{alltt}
Note that the unit interface {\tt unitid.sig}, if present, should be {\tt use}'ed in the interactive system,
since the interface declares a signature that is referred to in {\tt unitid.sml}, and may be referred to
in other units that depend on unit {\tt unitid}.
A structure-mode unit interface has two effects: it (a) declares a signature and (b)
serves to constrain the structure defined in the unit implementation.
\subsubsection*{Structure-mode unit implementation (in file {\tt unitid.sml})}
\begin{tabular}{lllll}
{\it unitimp\/} & ::=
& {\tt structure {\it unitid\/} = {\it modexp\/}} & structure \\
& & {\tt structure {\it unitid\/} :> {\it unitid\/} = {\it modexp}}
& structure with
signature \\
& & {\it cdec\/} & core declaration & deprecated\\[2ex]
{\it cdec\/} & ::= & {\tt val {\it tyvarseq\/} {\it valbind\/}} & value declaration\\
& & {\tt fun {\it tyvarseq\/} {\it fvalbind\/}} & function declaration\\
& & {\tt type {\it typbind\/}} & type declaration\\
& & {\tt datatype {\it datbind\/} \la\ withtype {\it typbind\/} \ra}
& datatype declaration\\
& & {\tt datatype {\it tycon\/} = datatype {\it tyconpath\/}}
& datatype replication\\
& & {\tt abstype {\it datbind\/} \la\ withtype {\it typbind\/} \ra}
& abstype declaration\\
& & \hspace{1.5cm}{\tt with {\it dec\/} end}\\
& & {\tt exception {\it exbind\/}} & exception declaration\\
& & {\tt local {\it dec\/}\et\ in {\it dec\/}\to\ end}
& local declaration\\
& & {\tt open {\it longstrid\/}\et\ $\cdots$ {\it longstrid\/}\n}
& open declaration, $n\geq 1$\\
& & & empty declaration\\
& & {\tt {\it cdec\/}\et\ \la;\ra\ {\it cdec\/}\to}
& sequential declaration\\
& & {\tt infix \la{\it d\/}\ra\ $id_1 \cdots id_n$} & infix (left)
directive, $n\geq 1$\\
& & {\tt infixr \la{\it d\/}\ra\ $id_1 \cdots id_n$} & infix (right)
directive, $n\geq 1$\\
& & {\tt nonfix $id_1 \cdots id_n$} & nonfix directive, $n\geq
1$\\[2ex]
\end{tabular}
\subsubsection*{Structure-mode unit interface (in file {\tt unitid.sig})}
\begin{tabular}{lllll}
{\it unitint\/} & ::=
& {\tt signature} {\it unitid} {\tt =} {\it sigexp\/}
& signature binding \\
& & {\it cspec\/} & core specification & deprecated \\[2ex]
{\it cspec} & ::= & {\tt val} {\it tyvarseq\/} {\it valdesc} & value specification & \x[\ref{valspec}] \\
%& & {\tt val} {\it tyvarseq} {\it valdesc} & value specification & \x \\
& & {\tt type} {\it typdesc} & abstract type \\
& & {\tt type} {\it typbind} & type abbreviation \\
& & {\tt eqtype} {\it typdesc} & abstract equality type\\
& & {\tt datatype} {\it datdesc} \la\ {\tt withtype} {\it typbind\/} \ra\ &
datatype with typbind & \x[\ref{datatypespec}]\\
& & {\tt datatype {\it tycon\/} = datatype {\it tyconpath\/}}
& datatype replication\\
& & {\tt exception} {\it exdesc} & exception\\
& & {\tt local} {\it lspec} {\tt in} {\it spec} {\tt end}
& local specifications & \x\\
& & & empty\\
& & {\tt {\it cspec} $\langle${;}$\rangle$ {\it cspec}} & sequential\\