-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptsms.tex
1725 lines (1576 loc) · 89.6 KB
/
ptsms.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
% !TEX root = omar-thesis.tex
\chapter{Parametric TLMs (pTLMs)}\label{chap:ptsms}
\begin{quote}\textit{You know me, I gotta put in a big tree.}
\begin{flushright} --- Bob Ross, \emph{The Joy of Painting}\end{flushright}
\end{quote}
% \begin{quote}\textit{The recent development of programming languages suggests that the simul\-taneous achievement of simplicity
% and generality in language design is a serious unsolved
% problem.}\begin{flushright}--- John Reynolds (1970) \cite{Reynolds70}\end{flushright}
% \end{quote}
% ~\\
~\\
\noindent
This chapter introduces \emph{parametric TLMs} (pTLMs). Parametric TLMs can be defined over a parameterized family of types, rather than just a single type, and the expansions that they generate can refer to supplied type and module parameters.
This chapter is organized like the preceding chapters. We begin in Sec. \ref{sec:parameterized-tsms-by-example} by introducing parametric TLMs by example in VerseML. In particular, we discuss type parameters in Sec. \ref{sec:type-parameters} and module parameters in Sec. \ref{sec:module-parameters}. We then develop a reduced calculus of parametric TLMs, $\miniVerseParam$, in Sec. \ref{sec:miniVerseP}.
\section{Parametric TLMs By Example}\label{sec:parameterized-tsms-by-example}
\subsection{Type Parameters}\label{sec:type-parameters}
Recall from Sec. \ref{sec:lists} the definition of the type-parameterized family of list types:
\begin{lstlisting}[numbers=none]
type list('a) = rec(self => Nil + Cons of 'a * self)
\end{lstlisting}
% \emph{Kinds} classify construction expressions, much like types classify expressions. Types are construction expressions of kind \li{T}, and type constructions are construction expressions of arrow kind. Here, \li{list} takes a single type parameter, so it has arrow kind \li{T -> T}.
% ML dialects commonly define derived syntactic forms for constructing and pattern matching over values of list type. VerseML, in contrast, does not build in derived list forms. Instead,
Figure \ref{fig:petsm-list} defines a \emph{parametric expression TLM} (peTLM) and a \emph{parametric pattern TLM} (ppTLM), both named \li{#\dolla#list}. These TLMs operate uniformly over this family of types.
\begin{figure}[h]
\begin{lstlisting}
syntax $list('a) at list('a) for expressions by
static fn(b : body) : parse_result(proto_expr) => (* ... *)
and for patterns by
static fn(b : body) : parse_result(proto_pat) => (* ... *)
end
\end{lstlisting}
\caption{The type-parameterized \texttt{\$list} TLMs.}
\label{fig:petsm-list}
\end{figure}
Line 1 specifies a single type parameter, \li{'a}. This type parameter appears in the type annotation, which establishes that:
\begin{enumerate}
\item The peTLM \li{#\dolla#list}, when applied to a type \li{T} and a generalized literal form, can only generate expansions of type \li{list(T)}.
\item The ppTLM \li{#\dolla#list}, when applied to a type \li{T} and a generalized literal form, can only generate expansions that match values of type \li{list(T)}.
\end{enumerate}
For example, we can apply \li{#\dolla#list} to \li{int} and a generalized literal form delimited by square brackets as follows:
% val y = $list int [3SURL, EURL4SURL, EURL5]
\begin{lstlisting}[numbers=none]
val x = $list int [xSURL, EURLySURL :: EURLxs]
\end{lstlisting}
The parse function (elided above for concision) segments the literal body into spliced expressions. The trailing spliced expression is prefixed by two colons (\li{SURL::EURL}), which the TLM takes to mean that it should be the tail of the list. The final expansion of the example above is equivalent to the following when the list value constructors are in scope:
\begin{lstlisting}[numbers=none]
val x = Cons(x, Cons(y, xs))
\end{lstlisting}
As in the preceding chapters, the expansion itself must use the explicit \li{fold} and \li{inj} operators rather than the list value constructors \li{Cons} and \li{Nil} due to the prohibition on context dependence.
\subsection{Module Parameters}\label{sec:module-parameters}
We can finally address the inconvenience of needing to use explicit \li{fold} and \li{inj} operators by defining a module-parameterized TLM.
Recall that in Figure \ref{fig:LIST}, we defined a signature \li{LIST} that exported the definition of \li{list} and specified the list value constructors (and some other values.) The definition of \li{#\dolla#list'} shown in Figure \ref{fig:ptsm-listprime} takes modules matching this signature as an additional parameter.
\begin{figure}[h]
\begin{lstlisting}[numbers=none]
syntax $list' (L : LIST) 'a at 'a L.list for expressions by
static fn(b : body) : parse_result(proto_expr) => (* ... *)
for patterns by
static fn(b : body) : parse_result(proto_pat) => (* ... *)
end
\end{lstlisting}
\caption{The type- and module-parameterized \texttt{\$list'} TLMs}
\label{fig:ptsm-listprime}
\end{figure}
% differing only in that any type parameter that the peTLM specifies can appear free in the generated expansion.
We can apply \li{#\dolla#list'} to the module \li{List} and the type \li{int} as follows:
\begin{lstlisting}[numbers=none]
val y = $list' List int [3SURL, EURL4SURL, EURL5]
val x = $list' List int [1SURL, EURL2SURL :: EURLy]
\end{lstlisting}
The expansion is:
\begin{lstlisting}[numbers=none]
val y = List.Cons(3, List.Cons(4, List.Cons(5, List.Nil)))
val x = List.Cons(1, List.Cons(2, y))
\end{lstlisting}
There is no need to use explicit \li{fold} and \li{inj} operators in this expansion, because the expansion projects the constructors out of the provided module parameter. The TLM itself did not assume that the module would be named \li{List} (internally, the proto-expansion refers to it as \li{L}.)
This makes matters simpler for the TLM provider, but there is a syntactic cost associated with supplying a module parameter at each TLM application site. To reduce this cost, VerseML supports partial parameter application in TLM abbreviations. For example, we can define \li{#\dolla#list} by partially applying \li{#\dolla#list'} as follows:
\begin{lstlisting}[numbers=none]
let syntax $list = $list' List
\end{lstlisting}
(This abbreviates both the expression and pattern TLMs -- sort qualifiers can be added to restrict the abbreviation if desired.)
% Similarly, in lieu of derived list pattern forms, we define the following \emph{parameterized pattern TLM} (ppTLM):
% \begin{lstlisting}[numbers=none]
% syntax $list('a) at list('a) for patterns {
% static fn(body : Body) : ParseResult(CEPat) => (* ... *)
% }
% \end{lstlisting}
% Again, Line 1 names the ppTLM \li{#\dolla#list} and specifies a single type parameter, \li{'a}. This type parameter appears in the type annotation, which specifies that \li{#\dolla#list}, when apply to a type \li{'a} and a generalized literal form, will only generate patterns that match values of type \li{list('a)}.
% For example, we can apply the ppTLM \li{#\dolla#list} and the \li{#\dolla#list} to define the polymorphic map function as follows.
% \begin{lstlisting}[numbers=none]
% fun map (f : 'a -> 'b) (x : list('a)) => match x {
% $list('a) [] => $list('b) []
% | $list('a) [hdSURL :: EURLtl] => $list('b) [f hdSURL :: EURLmap f tl]
% }
% \end{lstlisting}
% The expansion of this function definition, written textually, is:
% \begin{lstlisting}[numbers=none]
% fun map (f : 'a -> 'b) (x : list('a)) : 'b list => match x {
% Nil => Nil
% | Cons(hd, tl) => Cons(f hd, map f tl)
% }
% \end{lstlisting}
% This is somewhat unsatisfying, however, because the expansion is more concise than the unexpanded definition of \li{map}. To further reduce syntactic cost, we can designate \li{#\dolla#list} as the implicit TLM for both expressions and patterns at all types \li{'a list} around our definition of \li{map} as follows.
% \begin{lstlisting}[numbers=none]
% implicit syntax $list('a) in
% fun map (f : 'a -> 'b) (x : 'a list) : 'b list => match x {
% [] => []
% | [hdSURL :: EURLtl] => [f hdSURL :: EURLmap f tl]
% }
% end
% \end{lstlisting}
% By designating an implicit TLM, we no longer need to explicitly apply \li{#\dolla#list} within expressions in analytic position or patterns.
% When designating an implicit TLM, we assume that free type variables in the type annotation, e.g. here \li{'a}, range over all types. We can make this more explicit by specifying a type parameter explicitly as follows:
% \begin{lstlisting}[numbers=none]
% implicit syntax('a) $list('a) at list('a) in
% (* ... *)
% end
% \end{lstlisting}
% All type parameters must appear in the type annotation.
% \subsection{More Examples}
Module parameters also allow us to define TLMs that operate uniformly over module-parameterized families of abstract types. For example, the module-parameterized TLM \texttt{\$r} defined in Figure \ref{fig:param-tsm-r} supports the POSIX regex syntax for any type \li{R.t} where \li{R : RX}.
\begin{figure}[h]
\begin{lstlisting}
syntax $r(R : RX) at R.t by
static fn(b : body) : parse_result(proto_expr) => (* ... *)
end
\end{lstlisting}
\vspace{-8px}
\caption{The module-parameterized TLM \texttt{\$r}}
\label{fig:param-tsm-r}
\vspace{-4px}
\end{figure}
\noindent
For example, given \li{R1 : RX}, we can apply \li{#\dolla#r} as follows:
\begin{lstlisting}[numbers=none]
let dna = $r R1 /SURLA|T|G|CEURL/
\end{lstlisting}
The final expansion of this term is:
\begin{lstlisting}[numbers=none]
let dna = R1.Or(R1.Str "SSTRAESTR", R1.Or(R1.Str "SSTRTESTR",
R1.Or(R1.Str "SSTRGESTR", R1.Str "SSTRCESTR")))
\end{lstlisting}
To be clear: parameters are available to the generated expansion, but they are not available to the parse function that generates the expansion. For example, the following TLM definition is not well-typed because it refers to \li{M} from within the parse function:
\begin{lstlisting}[numbers=none]
syntax $badM(M : A) at T by
static fn(b : body) => let x = M.x in (* ... *)
end
\end{lstlisting}
(In the next chapter, we will define a mechanism that gives parse functions access to a common static environment.)
% \subsubsection{Queues}
% Consider the following signature for working with persistent queues:
% \begin{lstlisting}[numbers=none]
% signature QUEUE = sig
% type queue('a)
% val empty : queue('a)
% val insert : 'a * queue('a) -> queue('a)
% val remove : queue('a) -> option('a * queue('a))
% end
% \end{lstlisting}
% Structures that match this signature must define a type constructor \li{queue} of kind \li{T -> T} and three values -- \li{empty} introduces the empty queue, \li{insert} inserts a value onto the back of a queue, and \li{remove} removes the element at the front of the queue and returns it and the remaining queue, or \li{None} if the queue is empty.%one for inserting an item into a queue, and one for removing a value from a queue.
% There are many possible structures that implement this signature. For example, we can define a structure \li{ListQueue} that represents queues internally as lists, where the head of the list is the back of the queue. With this representation, \li{insert} is a constant time operation, but \li{remove} is a linear time operation. Alternatively, we might define a structure \li{TwoListQueue} that represents queues internally as a pair of lists, maintaining the invariant that one is the reverse of the other, so that both \li{insert} and \li{remove} are constant time operations (see \cite{harper1997programming} for the details of this and other possibilities).
% Regardless of the implementation that the client chooses, we would like for the client to be able to introduce queues more naturally and at lower syntactic cost than is possible by directly applying the functions specified by the signature above. In VerseML, we can give clients of structures matching the signature \li{QUEUE} this ability by defining the following parameterized expression TLM:
% \begin{lstlisting}[numbers=none]
% syntax $queue(Q : QUEUE)('a) at Q.queue('a) {
% static fn(body : Body) : ParseResult(CEExp) => (* ... *)
% }
% \end{lstlisting}
% This peTLM specifies one module parameter, \li{Q}, which must match the signature \li{QUEUE}, and one type parameter, \li{'a} (implicitly of kind \li{T}). These appear in the type annotation, which specifies that expansions that arise from applying \li{#\dolla#queue} to a module \li{Q : QUEUE} and a type \li{'a} will be of type \li{Q.queue('a)}. For example:
% \begin{lstlisting}
% val q = $queue TwoListQueue int [SURL> EURL1SURL, EURL2SURL, EURL3]
% val q' = $queue TwoListQueue int [qSURL > EURL4SURL, EURL5]
% \end{lstlisting}
% On Line 1, the initial angle bracket (\li{SURL>EURL}) indicates that the items are inserted in left-to-right order. The items in the queue are given as spliced subexpressions separated by commas. Line 2 inserts two additional items onto the back of the queue \li{q}. The expansion of this example, written textually, is:
% \begin{lstlisting}
% val q : TwoListQueue.queue(int) =
% TwoListQueue.insert(1,
% TwoListQueue.insert(2,
% TwoListQueue.insert(3,
% TwoListQueue.empty)))
% val q' : TwoListQueue.queue(int) =
% TwoListQueue.insert(4, TwoListQueue.insert(5, q))
% \end{lstlisting}
% Notice that the expansion can refer to the module parameter \li{TwoListQueue}.
% We can further reduce syntactic cost by defining a synonym for the partial application of \li{#\dolla#queue} to the module parameter \li{TwoListQueue}:
% \begin{lstlisting}[numbers=none]
% syntax $tlq = $queue TwoListQueue
% val q = $tlq int [SURL> EURL1SURL, EURL2SURL, EURL3]
% \end{lstlisting}
% We can further define a synonym for the partial application of \li{#\dolla#tlq} to a type parameter:
% \begin{lstlisting}[numbers=none]
% syntax $tlqi = $tlq int (* = $queue TwoListQueue int *)
% val q' = $tlqi [qSURL > EURL4SURL, EURL5]
% \end{lstlisting}
% \subsection{Module Parameters}
% VerseML also provides a module language based on the Standard ML module language \cite{MacQueen:1984:MSM:800055.802036}. The module language consists of \emph{module expressions} classified by \emph{signatures}. %Signatures specify type components, which may be opaque or transparent, value components, and module components.h
% %In Sec. \ref{sec:motivating-examples}, we gave several examples of signatures and discussed how one might introduce derived forms that across a module-parameterized family of types.
% Another way to reduce syntactic cost is by designating \li{#\dolla#queue Q 'a} the implicit TLM at all types of the form \li{Q.queue('a)} where \li{Q : QUEUE}. This is written as follows:
% \begin{lstlisting}[numbers=none]
% implicit syntax (Q : QUEUE) ('a) => $queue Q 'a in
% val q : TwoListQueue.queue(int) = [SURL> EURL1SURL, EURL2SURL, EURL3]
% val q' : TwoListQueue.queue(int) = [qSURL > EURL4SURL, EURL5]
% end
% \end{lstlisting}
% This designation is particularly useful for clients who need to construct a queue as an argument to a function. For example, consider a function
% \begin{lstlisting}[numbers=none]
% enqueue_jobs : Q.queue(Job) -> Ticket
% \end{lstlisting}
% for some module \li{Q : QUEUE} and types \li{Job} and \li{Ticket}. We can enqueue a sequence of jobs \li{j1} through \li{j4} under the TLM designation above as follows:
% \begin{lstlisting}[numbers=none]
% enqueue_jobs [SURL> EURLj1SURL, EURLj2SURL, EURLj3SURL, EURLj4]
% \end{lstlisting}
\vspace{-5px}
\section{\texorpdfstring{$\miniVerseParam$}{miniVerseP}}\label{sec:miniVerseP}
We will now define a reduced dialect of VerseML called $\miniVerseParam$ that supports parametric expression and pattern TLMs (peTLMs and ppTLMs.) This language, like $\miniVersePat$, consists of an unexpanded language (UL) defined by typed expansion to an expanded language (XL). The full definition of $\miniVerseParam$ is given in Appendix \ref{appendix:miniVerseParam} -- we will detail only particularly interesting constructs below.
\subsection{Syntax of the Expanded Language (XL)}\label{sec:P-expanded-terms}
\begin{figure}[p]
\[\begin{array}{lllllll}
\textbf{Sort} & & & \textbf{Operational Form}
%& \textbf{Stylized Form}
& \textbf{Description}\\
\mathsf{Sig} & \sigma & ::= & \asignature{\kappa}{u}{\tau}
%& \signature{u}{\kappa}{\tau}
& \text{signature}\\
\mathsf{Mod} & M & ::= & X
%& X
& \text{module variable}\\
&&& \astruct{c}{e}
%& \struct{c}{e}
& \text{structure}\\
&&& \aseal{\sigma}{M}
%& \seal{M}{\sigma}
& \text{seal}\\
&&& \amlet{\sigma}{M}{X}{M} %& \mlet{X}{M}{M}{\sigma}
& \text{definition}
\end{array}\]
\caption[Syntax of signatures and module expressions in $\miniVerseParam$]{Syntax of signatures and module expressions in $\miniVerseParam$}
\label{fig:P-modules-signatures}
\end{figure}
\begin{figure}[p]
\[\begin{array}{lrlllll}
\textbf{Sort} & & & \textbf{Operational Form}
%& \textbf{Stylized Form}
& \textbf{Description}\\
\mathsf{Kind} & \kappa & ::= & k & \text{kind variable}\\
&&& \akdarr{\kappa}{u}{\kappa}
%& \kdarr{u}{\kappa}{\kappa}
& \text{dependent function}\\
&&& \akunit
%& \kunit
& \text{nullary product}\\
&&& \akdbprod{\kappa}{u}{\kappa}
%& \kdbprod{u}{\kappa}{\kappa}
& \text{dependent product}\\
%&&& \akdprodstd & \kdprodstd & \text{labeled dependent product}\\
&&& \akty
%& \kty
& \text{type}\\
&&& \aksing{\tau}
%& \ksing{\tau}
& \text{singleton}\\
\mathsf{Con} & c, \tau & ::= & u
%& u
& \text{construction variable}\\
&&& t
%& t
& \text{type variable}
\\
&&& \acabs{u}{c}
%& \cabs{u}{c}
& \text{abstraction}\\
&&& \acapp{c}{c}
%& \capp{c}{c}
& \text{application}\\
&&& \actriv
%& \ctriv
& \text{trivial}\\
&&& \acpair{c}{c}
% & \cpair{c}{c}
& \text{pair}\\
&&& \acprl{c}
%& \cprl{c}
& \text{left projection}\\
&&& \acprr{c}
%& \cprr{c}
& \text{right projection}\\
%&&& \adtplX & \dtplX & \text{labeled dependent tuple}\\
%&&& \adprj{\ell}{c} & \prj{c}{\ell} & \text{projection}\\
&&& \aparr{\tau}{\tau}
%& \parr{\tau}{\tau}
& \text{partial function}\\
&&& \aallu{\kappa}{u}{\tau}
%& \forallu{u}{\kappa}{\tau}
& \text{polymorphic}\\
&&& \arec{t}{\tau}
%& \rect{t}{\tau}
& \text{recursive}\\
&&& \aprod{\labelset}{\mapschema{\tau}{i}{\labelset}}
%& \prodt{\mapschema{\tau}{i}{\labelset}}
& \text{labeled product}\\
&&& \asum{\labelset}{\mapschema{\tau}{i}{\labelset}}
%& \sumt{\mapschema{\tau}{i}{\labelset}}
& \text{labeled sum}\\
&&& \amcon{M}
%& \mcon{M}
& \text{construction component}
\end{array}\]
\caption[Syntax of kinds and constructions in $\miniVerseParam$]{Syntax of kinds and constructions in $\miniVerseParam$. By convention, we choose the metavariable $\tau$ for constructions that, in well-formed terms, must necessarily be of kind $\kty$, and the metavariable $c$ otherwise. Similarly, we use construction variables $t$ to stand for constructions of kind $\kty$, and construction variables $u$ otherwise. Kind variables, $k$, are necessary only for the metatheory.}
\label{fig:P-kinds-constructors}
\end{figure}
\begin{figure}
\[\begin{array}{lllllll}
\textbf{Sort} & & & \textbf{Operational Form}
%& \textbf{Stylized Form}
& \textbf{Description}\\
\mathsf{Exp} & e & ::= & x
%& x
& \text{variable}\\
&&& \aelam{\tau}{x}{e}
%& \lam{x}{\tau}{e}
& \text{abstraction}\\
&&& \aeap{e}{e}
%& \ap{e}{e}
& \text{application}\\
&&& \aeclam{\kappa}{u}{e} %& \clam{u}{\kappa}{e}
& \text{construction abstraction}\\
&&& \aecap{e}{c} %& \cAp{e}{c}
& \text{construction application}\\
&&& \aefold{e} %& \fold{e}
& \text{fold}\\
&&& \aeunfold{e} %& \unfold{e}
& \text{unfold}\\
&&& \aetpl{\labelset}{\mapschema{e}{i}{\labelset}}
%& \tpl{\mapschema{e}{i}{\labelset}}
& \text{labeled tuple}\\
&&& \aepr{\ell}{e}
%& \prj{e}{\ell}
& \text{projection}\\
&&& \aein{\ell}{e}
%& \inj{\ell}{e}
& \text{injection}\\
&&& \aematchwith{n}{e}{\seqschemaX{r}}
%& \matchwith{e}{\seqschemaX{r}}
& \text{match}\\
&&& \amval{M}
%& \mval{M}
& \text{value component}\\
\mathsf{Rule} & r & ::= & \aematchrule{p}{e}
%& \matchrule{p}{e}
& \text{rule}\\
\mathsf{Pat} & p & ::= & x
%& x
& \text{variable pattern}\\
&&& \aewildp
%& \wildp
& \text{wildcard pattern}\\
&&& \aefoldp{p}
%& \foldp{p}
& \text{fold pattern}\\
&&& \aetplp{\labelset}{\mapschema{p}{i}{\labelset}}
%& \tplp{\mapschema{p}{i}{\labelset}}
& \text{labeled tuple pattern}\\
&&& \aeinjp{\ell}{p}
%& \injp{\ell}{p}
& \text{injection pattern}
\end{array}\]
\caption[Syntax of expanded expressions, rules and patterns in $\miniVerseParam$]{Syntax of expanded expressions, rules and patterns in $\miniVerseParam$}
\label{fig:P-expanded-terms}
\end{figure}
Figure \ref{fig:P-modules-signatures} defines the syntax of the \emph{expanded module language}. Figure \ref{fig:P-kinds-constructors} defines the syntax of the \emph{expanded type construction language}. Figure \ref{fig:P-expanded-terms} defines the syntax of the \emph{expanded expression language}.
\subsection{Statics of the Expanded Language}
The module and type construction languages are based closely on those defined by Harper in \emph{PFPL} \cite{pfpl}. These languages, in turn, are based on the languages developed by Lee et al. \cite{conf/popl/LeeCH07}, and also by Dreyer \cite{dreyer2005understanding}. All of these incorporate Stone and Harper's \emph{dependent singleton kinds} formalism to track type identity \cite{stone2006extensional}. The expression language is similar to that of $\miniVersePat$, defined in Chapter \ref{chap:uptsms}.
The \emph{statics of the expanded language} is defined by a collection of judgements that we organize into three groups.
The first group of judgements, which we refer to as the \emph{statics of the expanded module language}, define the statics of expanded signatures and module expressions.
\vspace{5px}
$\begin{array}{ll}
\textbf{Judgement Form} & \textbf{Description}\\
\issigX{\sigma} & \text{$\sigma$ is a signature }\\
\sigequalX{\sigma}{\sigma'} & \text{$\sigma$ and $\sigma'$ are definitionally equal signatures}\\
\sigsubX{\sigma}{\sigma'} & \text{$\sigma$ is a sub-signature of $\sigma'$}\\
\hassigX{M}{\sigma} & \text{$M$ matches $\sigma$}\\
\ismvalX{M} & \text{$M$ is, or stands for, a module value}
\end{array}$
\vspace{5px}
The second group of judgements, which we refer to as the \emph{statics of the expanded type construction language}, define the statics of expanded kinds and constructions.
\vspace{5px}
$\begin{array}{ll}
\textbf{Judgement Form} & \textbf{Description}\\
\iskindX{\kappa} & \text{$\kappa$ is a kind}\\
\kequalX{\kappa}{\kappa'} & \text{$\kappa$ and $\kappa'$ are definitionally equal kinds}\\
\ksubX{\kappa}{\kappa'} & \text{$\kappa$ is a subkind of $\kappa'$}\\
\haskindX{c}{\kappa} & \text{$c$ has kind $\kappa$}\\
\cequalX{c}{c'}{\kappa} & \text{$c$ and $c'$ are equivalent as constructions of kind $\kappa$}
\end{array}$
\vspace{5px}
The third group of judgements, which we refer to as the \emph{statics of the expanded expression language}, define the statics of types, expanded expressions, rules and patterns. Types are constructions of kind $\akty$. We use the metavariable $\tau$ rather than $c$ for types.
\vspace{5px}
$\begin{array}{ll}
\textbf{Judgement Form} & \textbf{Description}\\
% \istypeP{\Omega}{\tau} & \text{$\tau$ is a well-formed type}\\
% \tequalPX{\tau}{\tau'} & \text{$\tau$ and $\tau'$ are definitionally equal types}\\
\issubtypePX{\tau}{\tau'} & \text{$\tau$ is a subtype of $\tau'$}\\
\hastypeP{\Omega}{e}{\tau} & \text{$e$ is assigned type $\tau$}\\
\ruleTypeP{\Omega}{r}{\tau}{\tau'} & \text{$r$ takes values of type $\tau$ to values of type $\tau'$}\\
\patTypeP{\Omega'}{p}{\tau} & \text{$p$ matches values of type $\tau$ and generates hypotheses $\Omega'$}
\end{array}$
\vspace{5px}
A \emph{unified context}, $\Omega$, is a finite function over module, expression and construction variables.
We write
\begin{itemize}
\item $\Omega, X : \sigma$ when $X \notin \domof{\Omega}$ and $\issigX{\sigma}$ for the extension of $\Omega$ with a mapping from $X$ to the hypothesis $X : \sigma$.
\item $\Omega, x : \tau$ when $x \notin \domof{\Omega}$ and $\haskindX{\tau}{\akty}$ for the extension of $\Omega$ with a mapping from $x$ to the hypothesis $x : \tau$
\item $\Omega, u :: \kappa$ when $u \notin \domof{\Omega}$ and $\iskindX{\kappa}$ for the extension of $\Omega$ with a mapping from $u$ to the hypothesis $u :: \kappa$
\end{itemize}
A well-formed unified context is one that can be constructed by some sequence of such extensions, starting from the empty context, $\emptyset$. We identify unified contexts up to exchange and contraction in the usual manner.
The complete set of rules is given in Appendix \ref{appendix:P-statics}. A comprehensive introductory account of these constructs is beyond the scope of this work (see \cite{pfpl}.) Instead, let us summarize the key features of the expanded language by example.
Modules take the form $\astruct{c}{e}$, following a \emph{phase-splitting} approach -- the construction components of the module are ``tupled'' into a single construction component, $c$, and the value components of the module are ``tupled'' into a single value component, $e$ \cite{harper1989higher}. Signatures, $\sigma$, are also split in this way -- a single \emph{kind}, $\kappa$, classifies the construction component and a single type, $\tau$, classifies the value component of the classified module. The type can refer to the construction component through a mediating construction variable, $u$. The key rule is reproduced below:
\begin{equation*}\tag{\ref{rule:hassig-struct}}
\inferrule{
\haskindX{c}{\kappa}\\
\hastypeP{\Omega}{e}{[c/u]\tau}
}{
\hassigX{\astruct{c}{e}}{\asignature{\kappa}{u}{\tau}}
}
\end{equation*}
For example, consider the VerseML signature and the corresponding $\miniVerseParam$ signature in Figure \ref{fig:corresponding-signatures}. The kind on the right (Lines 1-3) is a \emph{dependent product kind} and the type (Lines 4-5) is a product type. Let us consider these in turn.
\begin{figure}
\begin{minipage}{0.35\textwidth}
\begin{lstlisting}
sig
type t
type t' = t * t
val x : t
val y : t -> t'
end
\end{lstlisting}
\end{minipage}
\begin{minipage}{0.5\textwidth}\vspace{3px}
{\footnotesize\[
\begin{array}{l}
\asignature{\akdbprod{\\
\quad\quad \akty}{t}{\\
\quad\quad \aksing{
\aprod{\lbltxt{1}; \lbltxt{2}}{
\mapitem{\lbltxt{1}}{t}; \mapitem{\lbltxt{2}}{t}
}
}}\\}{u}{
\aprod{\lbltxt{x}; \lbltxt{y}}{
\mapitem{\lbltxt{x}}{\acprl{u}}; \\
\quad\quad \mapitem{\lbltxt{y}}{\aparr{
\acprl{u}
}{
\acprr{u}
}}
}\\
}
\end{array}
\]}
\end{minipage}
\caption{A VerseML signature and the corresponding $\miniVerseParam$ signature}
\label{fig:corresponding-signatures}
\vspace{-10px}
\end{figure}
On Lines 2-3 (left), we specified an abstract type component \li{t}, and then a translucent type component \li{t'} equal to \li{t * t}. Abstract type components have kind $\akty$, so the first component of the dependent product kind is $\akty$ (Line 2, right). The construction variable $t$ stands for the first component in the second component of the dependent product kind. The second component is not held abstract, so it is classified by a corresponding \emph{singleton kind}, rather than by the kind $\akty$ (Line 3, right). A singleton kind $\aksing{\tau}$ classifies only those types definitionally equal to $\tau$. A subkinding system is necessary to ensure that constructions of singleton kind can appear where a construction of kind $\akty$ is needed -- the key rule is reproduced below:
\begin{equation*}\tag{\ref{rule:ksub-sing}}
\inferrule{
\haskindX{\tau}{\akty}
}{
\ksubX{\aksing{\tau}}{\akty}
}
\end{equation*}
Lines 4-5 (right) define a product type that classifies the value component of matching modules. The construction variable \li{u} stands for the construction component of the matching module. The left- and right-projection operations $\acprl{c}$ and $\acprr{c}$ on the right correspond to \li{t} and \li{t'} on the left. (In practice, we would use labeled dependent product kinds, but for simplicity, we stick to binary dependent product kinds here.)
Consider another example: the VerseML \li{LIST} signature from Figure \ref{fig:LIST}, partially reproduced below:
\begin{lstlisting}
sig
type list('a) = rec(self => Nil + Cons of 'a * self)
val Nil : list('a)
val Cons : 'a * list('a) -> list('a)
(* ... *)
end
\end{lstlisting}
This signature corresponds to the $\miniVerseParam$ signature $\sigma_\texttt{LIST}$ defined in Figure \ref{fig:LIST-mini}.
\begin{figure}
\[
\arraycolsep=1px\begin{array}{ll}
\sigma_\texttt{LIST} & \defeq \asignature{\kappa_\texttt{LIST}}{list}{\tau_\texttt{LIST}}\\
\kappa_\texttt{LIST} & \defeq \akdarr{\akty}{\alpha}{\aksing{
\arec{self}{
\asum{L_\texttt{list}}{\\
& \quad\quad
\mapitem{\lbltxt{Nil}}{\aprod{}{}}; \\
& \quad\quad
\mapitem{\lbltxt{Cons}}{
\aprod{\lbltxt{1}; \lbltxt{2}}{
\mapitem{\lbltxt{1}}{\alpha};
\mapitem{\lbltxt{2}}{self}
}
}
}
}
}}\\
L_\texttt{list} & \defeq \lbltxt{Nil}, \lbltxt{Cons}\\
\tau_\texttt{LIST} & \defeq \aprod{L_\texttt{list}}{\\&
\quad\quad \mapitem{\lbltxt{Nil}}{
\aallu{\akty}{\alpha}{\acapp{list}{\alpha}}
}; \\&
\quad\quad \mapitem{\lbltxt{Cons}}{
\aallu{\akty}{\alpha}{
\aparr{\\&\quad\quad\quad
\aprod{\lbltxt{1}; \lbltxt{2}}{
\mapitem{\lbltxt{1}}{\alpha};
\mapitem{\lbltxt{2}}{\acapp{list}{\alpha}}
}
}{\\&\quad\quad\quad
\acapp{list}{\alpha}
}
}
}
}
\end{array}
\]
\caption{The $\miniVerseParam$ encoding of the \texttt{LIST} signature}
\label{fig:LIST-mini}
\end{figure}
Here, the signature specifies only a single construction component, so no tupling of the construction component is necessary. This single construction component is a type function, so it has dependent function kind: the argument kind is $\akty$ and the return kind is a singleton kind, because the type function is not abstract. (Had we held the type function abstract, its kind would instead be $\akdarr{\akty}{\_}{\akty}$.)
%A well-formed unified inner context is one where there are no cycles in the dependency graph between the hypotheses (constructed in the obvious manner) and for each hypothesis, the construction, kinds or signature involved is well-formed relative to the unified inner context.
At the top level, a program consists of a module expression, $M$. The module let binding form allows the programmer to bind a module to a module variable, $X$:
\begin{equation*}\tag{\ref{rule:hassig-let}}
\inferrule{
\hassigX{M}{\sigma}\\
\issigX{\sigma'}\\
\hassig{\Omega, X : \sigma}{M'}{\sigma'}
}{
\hassigX{\amlet{\sigma'}{M}{X}{M'}}{\sigma'}
}
\end{equation*}
The construction projection form, $\amcon{M}$, allows us to refer to the construction component of $M$ within a construction appearing in $M'$. The kinding rule for this form is reproduced below:
\begin{equation*}\tag{\ref{rule:haskind-stat}}
\inferrule{
\ismvalX{M}\\
\hassigX{M}{\asignature{\kappa}{u}{\tau}}
}{
\haskindX{\amcon{M}}{\kappa}
}
\end{equation*}
Similarly, the value projection form, $\amval{M}$, projects out the value component of $M$ within an expression appearing in $M'$. The typing rule for this form is reproduced below:
\begin{equation*}\tag{\ref{rule:hastypeP-dyn}}
\inferrule{
\ismvalX{M}\\
\hassigX{M}{\asignature{\kappa}{u}{\tau}}
}{
\hastypeP{\Omega}{\amval{M}}{[\amcon{M}/u]\tau}
}
\end{equation*}
The first premise of both of these rules requires that $M$ be, or stand for, a \emph{module value}, according to the following rules:
\begin{equation*}\tag{\ref{rule:ismval-struct}}
\inferrule{ }{
\ismvalX{\astruct{c}{e}}
}
\end{equation*}
\begin{equation*}\tag{\ref{rule:ismval-var}}
\inferrule{ }{
\ismval{\Omega, X : \sigma}{X}
}
\end{equation*}
The reason for this restriction has to do with the \emph{sealing} operation:
\begin{equation*}\tag{\ref{rule:hassig-seal}}
\inferrule{
\issigX{\sigma}\\
\hassigX{M}{\sigma}
}{
\hassigX{\aseal{\sigma}{M}}{\sigma}
}
\end{equation*}
Sealing enforces \emph{representation independence} -- the abstract construction components of a sealed module are not treated as equivalent to those of any other sealed module within the program. In other words, sealing is \emph{generative}. The module value restriction above achieves this behavior by simple syntactic means -- a sealed module is not a module value, so all sealed modules have to be bound to distinct module variables.
The judgements above obey standard lemmas, including Weakening, Substitution and Decomposition (see Appendix \ref{appendix:P-statics}.)
We omit certain features of the ML module system in $\miniVerseParam$, such as its support for hierarchical modules and functors. Our formulation also does not support ``width'' subtyping and subkinding for simplicity. These are straightforward extensions of $\miniVerseParam$, but because their inclusion would not change the semantics of parametric TLMs, we did not include them (see \cite{pfpl} for a discussion of these features.)
\subsection{Structural Dynamics}
The structural dynamics of modules is defined as a transition system, and is organized around judgements of the following form:
\vspace{10px}
$\begin{array}{ll}
\textbf{Judgement Form} & \textbf{Description}\\
\stepsU{M}{M'} & \text{$M$ transitions to $M'$}\\
\isvalP{M} & \text{$M$ is a module value}\\
\matchfail{M} & \text{$M$ raises match failure}
\end{array}$
\vspace{10px}
The structural dynamics of expressions is also defined as a transition system, and is organized around judgements of the following form:
\vspace{10px}
$\begin{array}{ll}
\textbf{Judgement Form} & \textbf{Description}\\
\stepsU{e}{e'} & \text{$e$ transitions to $e'$}\\
\isvalP{e} & \text{$e$ is a value}\\
\matchfail{e} & \text{$e$ raises match failure}
\end{array}$
\vspace{10px}
We also define auxiliary judgements for \emph{iterated transition}, $\multistepU{e}{e'}$, and \emph{evaluation}, $\evalU{e}{e'}$, of expressions.
\begingroup
\def\thetheorem{\ref{defn:iterated-transition-P}}
\begin{definition}[Iterated Transition] Iterated transition, $\multistepU{e}{e'}$, is the reflexive, transitive closure of the transition judgement, $\stepsU{e}{e'}$.\end{definition}
% \addtocounter{theorem}{-1}
\endgroup
\begingroup
\def\thetheorem{\ref{defn:evaluation-P}}
\begin{definition}[Evaluation] $\evalU{e}{e'}$ iff $\multistepU{e}{e'}$ and $\isvalU{e'}$. \end{definition}
% \addtocounter{theorem}{-1}
\endgroup
As in previous chapters, our subsequent developments do not make mention of particular rules in the dynamics, so we do not produce these details here. Instead, it suffices to state the following conditions.
The Preservation condition ensures that evaluation preserves typing.
\begingroup
\def\thetheorem{\ref{condition:preservation-P}}
\begin{condition}[Preservation] ~
\begin{enumerate}
\item If $\hassig{}{M}{\sigma}$ and $\stepsU{M}{M'}$ then $\hassig{}{M}{\sigma}$.
\item If $\hastypeUC{e}{\tau}$ and $\stepsU{e}{e'}$ then $\hastypeUC{e'}{\tau}$.
\end{enumerate}
\end{condition}
\endgroup
The Progress condition ensures that evaluation of a well-typed expanded expression cannot ``get stuck''. We must consider the possibility of match failure in this condition.
\begingroup
\def\thetheorem{\ref{condition:progress-P}}
\begin{condition}[Progress] ~
\begin{enumerate}
\item If $\hassig{}{M}{\sigma}$ then either $\isvalU{M}$ or $\matchfail{M}$ or there exists an $M'$ such that $\stepsU{M}{M'}$.
\item If $\hastypeUC{e}{\tau}$ then either $\isvalU{e}$ or $\matchfail{e}$ or there exists an $e'$ such that $\stepsU{e}{e'}$.
\end{enumerate}
\end{condition}
% \addtocounter{theorem}{-1}
\endgroup
Together, these two conditions constitute the Type Safety Condition.
\begin{figure}[p] \vspace{-15px}
$\arraycolsep=4pt\begin{array}{lllllll}
\textbf{Sort} & &
%& \textbf{Operational Form}
& \textbf{Stylized Form} & \textbf{Description}\\
\mathsf{USig} & \usigma & ::=
%& \ausignature{\ukappa}{\uu}{\utau}
& \signature{\uu}{\ukappa}{\utau} & \text{signature}\\
\mathsf{UMod} & \uM & ::=
%& \uX
& \uX & \text{module identifier}\\
&&
%& \austruct{\uc}{\ue}
& \struct{\uc}{\ue} & \text{structure}\\
&&
%& \auseal{\usigma}{\uM}
& \seal{\uM}{\usigma} & \text{seal}\\
&&
%& \aumlet{\usigma}{\uM}{\uX}{\uM}
& \mlet{\uX}{\uM}{\uM}{\usigma} & \text{definition}\\
\LCC &&
%& \lightgray
& \color{Yellow} & \color{Yellow}\\
&&
%& \aumdefpetsm{\urho}{e}{\tsmv}{\uM}
& \defpetsm{\tsmv}{\urho}{e}{\uM} & \text{peTLM definition}\\
%&&& & \texttt{expressions}~\{e\}~\texttt{in}~\uM\\
&&
%& \aumletpetsm{\uepsilon}{\tsmv}{\uM}
& \uletpetsm{\tsmv}{\uepsilon}{\uM} & \text{peTLM binding}\\
% &&& & \texttt{expressions}~\texttt{in}~\uM\\
% &&& ... & ... & \text{peTLM designation}\\
&&
%& \audefpptsm{\urho}{e}{\tsmv}{\uM}
& \defpptsm{\tsmv}{\urho}{e}{\uM} & \text{ppTLM definition}\\
% &&& & \texttt{patterns}~\{e\}~\texttt{in}~\uM\\
&&
%& \auletpptsm{\uepsilon}{\tsmv}{\uM}
& \uletpptsm{\tsmv}{\uepsilon}{\uM} & \text{ppTLM binding}\ECC%
% &&& & \texttt{patterns}~\texttt{in}~\uM\\
% &&& ... & ... & \text{ppTLM designation}\ECC
\end{array}$%\vspace{-5px}
\caption[Syntax of unexpanded module expressions and signatures in $\miniVerseParam$]{Syntax of unexpanded module expressions and signatures in $\miniVerseParam$}%\vspace{-5px}
\label{fig:P-unexpanded-modules-signatures}
\end{figure}
\begin{figure}[p] \vspace{-10px}
\[\begin{array}{lrlllll}
\textbf{Sort} & &
%& \textbf{Operational Form}
& \textbf{Stylized Form} & \textbf{Description}\\
\mathsf{UKind} & \ukappa & ::=
%& \aukdarr{\ukappa}{\uu}{\ukappa}
& \kdarr{\uu}{\ukappa}{\ukappa} & \text{dependent function}\\
&&
%& \aukunit
& \kunit & \text{nullary product}\\
&&
%& \aukdbprod{\ukappa}{\uu}{\ukappa}
& \kdbprod{\uu}{\ukappa}{\ukappa} & \text{dependent product}\\
%&&& \akdprodstd & \kdprodstd & \text{labeled dependent product}\\
&&
%& \aukty
& \kty & \text{type}\\
&&
%& \auksing{\utau}
& \ksing{\utau} & \text{singleton}\\
\mathsf{UCon} & \uc, \utau & ::=
%& \uu
& \uu & \text{construction identifier}\\
&&
%& \ut
& \ut & \\
&&
%& \aucasc{\ukappa}{\uc}
& \casc{\uc}{\ukappa} & \text{ascription}\\
&&
%& \aucabs{\uu}{\uc}
& \cabs{\uu}{\uc} & \text{abstraction}\\
&&
%& \aucapp{c}{c}
& \capp{c}{c} & \text{application}\\
&&
%& \auctriv
& \ctriv & \text{trivial}\\
&&
%& \aucpair{\uc}{\uc}
& \cpair{\uc}{\uc} & \text{pair}\\
&&
%& \aucprl{\uc}
& \cprl{\uc} & \text{left projection}\\
&&
%& \aucprr{\uc}
& \cprr{\uc} & \text{right projection}\\
%&&& \adtplX & \dtplX & \text{labeled dependent tuple}\\
%&&& \adprj{\ell}{c} & \prj{c}{\ell} & \text{projection}\\
&&
%& \auparr{\utau}{\utau}
& \parr{\utau}{\utau} & \text{partial function}\\
&&
%& \auallu{\ukappa}{\uu}{\utau}
& \forallu{\uu}{\ukappa}{\utau} & \text{polymorphic}\\
&&
%& \aurec{\ut}{\utau}
& \rect{\ut}{\utau} & \text{recursive}\\
&&
%& \auprod{\labelset}{\mapschema{\utau}{i}{\labelset}}
& \prodt{\mapschema{\utau}{i}{\labelset}} & \text{labeled product}\\
&&
%& \ausum{\labelset}{\mapschema{\utau}{i}{\labelset}}
& \sumt{\mapschema{\utau}{i}{\labelset}} & \text{labeled sum}\\
&&
%& \aumcon{\uX}
& \mcon{\uX} & \text{construction component}
\end{array}\]%\vspace{-5px}
\caption[Syntax of unexpanded kinds and constructions in $\miniVerseParam$]{Syntax of unexpanded kinds and constructions in $\miniVerseParam$}\vspace{-10px}
\label{fig:P-unexpanded-kinds-constructors}
\end{figure}
% \clearpage
\begin{figure}[p]
\[\begin{array}{lllllll}
\textbf{Sort} & &
%& \textbf{Operational Form}
& \textbf{Stylized Form} & \textbf{Description}\\
\mathsf{UExp} & \ue & ::=
%& \ux
& \ux & \text{identifier}\\
&&
% & \auasc{\utau}{\ue}
& \asc{\ue}{\utau} & \text{ascription}\\
&&
% & \auletsyn{\ux}{\ue}{\ue}
& \letsyn{\ux}{\ue}{\ue} & \text{value binding}\\
% &&
%& \auanalam{\ux}{\ue}
% & \analam{\ux}{\ue} & \text{abstraction (unannotated)}\\
&&
%& \aulam{\utau}{\ux}{\ue}
& \lam{\ux}{\utau}{\ue} & \text{abstraction}\\
&&
%& \auap{\ue}{\ue}
& \ap{\ue}{\ue} & \text{application}\\
&&
%& \auclam{\ukappa}{\uu}{\ue}
& \clam{\uu}{\ukappa}{\ue} & \text{construction abstraction}\\
&&
%& \aucap{\ue}{\uc}
& \cAp{\ue}{\uc} & \text{construction application}\\
&&
%& \auanafold{\ue}
& \fold{\ue} & \text{fold}\\
&&
%& \auunfold{\ue}
& \unfold{\ue} & \text{unfold}\\
&&
%& \autpl{\labelset}{\mapschema{\ue}{i}{\labelset}}
& \tpl{\mapschema{\ue}{i}{\labelset}} & \text{labeled tuple}\\
&&
%& \aupr{\ell}{\ue}
& \prj{\ue}{\ell} & \text{projection}\\
&&
%& \auanain{\ell}{\ue}
& \inj{\ell}{\ue} & \text{injection}\\
&&
%& \aumatchwithb{n}{\ue}{\seqschemaX{\urv}}
& \matchwith{\ue}{\seqschemaX{\urv}} & \text{match}\\
&&
%& \aumval{\uX}
& \mval{\uX} & \text{value component}\\
\LCC &&
% %& \color{Yellow}
& \color{Yellow} & \color{Yellow} \\
% &&& \audefpetsm{\urho}{e}{\tsmv}{\ue} & \texttt{syntax}~\tsmv~\texttt{at}~\urho~\texttt{for} & \text{peTLM definition}\\
% &&& & \texttt{expressions}~\{e\}~\texttt{in}~\ue\\
% &&& \auletpetsm{\uepsilon}{\tsmv}{\ue} & \texttt{let}~\texttt{syntax}~\tsmv=\uepsilon~\texttt{for} & \text{peTLM binding}\\
% &&& & \texttt{expressions}~\texttt{in}~\ue\\
% &&& ... & ... & \text{peTLM designation}\\
&&
%& \auappetsm{b}{\uepsilon}
& \utsmap{\uepsilon}{b} & \text{peTLM application}\ECC\\%\ECC
% &&& \auelit{b} & {\lit{b}} & \text{peTLM unadorned literal}\\
% &&& \audefpptsm{\urho}{e}{\tsmv}{\ue} & \texttt{syntax}~\tsmv~\texttt{at}~\urho~\texttt{for} & \text{ppTLM definition}\\
% &&& & \texttt{patterns}~\{e\}~\texttt{in}~\ue\\
% &&& \auletpptsm{\uepsilon}{\tsmv}{\ue} & \texttt{let}~\texttt{syntax}~\tsmv=\uepsilon~\texttt{for} & \text{ppTLM binding}\\
% &&& & \texttt{patterns}~\texttt{in}~\ue\\
% &&& ... & ... & \text{ppTLM designation}\\\ECC
\mathsf{URule} & \urv & ::=
%& \aumatchrule{\upv}{\ue}
& \matchrule{\upv}{\ue} & \text{match rule}\\
\mathsf{UPat} & \upv & ::=
%& \ux
& \ux & \text{identifier pattern}\\
&&
%& \auwildp
& \wildp & \text{wildcard pattern}\\
&&
%& \aufoldp{\upv}
& \foldp{\upv} & \text{fold pattern}\\
&&
%& \autplp{\labelset}{\mapschema{\upv}{i}{\labelset}}
& \tplp{\mapschema{\upv}{i}{\labelset}} & \text{labeled tuple pattern}\\
&&
% & \auinjp{\ell}{\upv}
& \injp{\ell}{\upv}
& \text{injection pattern}\\
\LCC &&
%& \lightgray
& \color{Yellow} & \color{Yellow}\\
&&
%& \auappptsm{b}{\uepsilon}
& \utsmap{\uepsilon}{b} & \text{ppTLM application}\ECC
% &&& \auplit{b} & \lit{b} & \text{ppTLM unadorned literal}\ECC
\end{array}\]
\caption[Syntax of unexpanded expressions, rules and patterns in $\miniVerseParam$]{Syntax of unexpanded expressions, rules and patterns in $\miniVerseParam$}
\label{fig:P-unexpanded-terms}
\end{figure}
% \clearpage
\begin{figure}[p]
\[\begin{array}{lllllll}
\textbf{Sort} & &
%& \textbf{Operational Form}
& \textbf{Stylized Form}
& \textbf{Description}\\
\LCC \color{Yellow}&\color{Yellow}& \color{Yellow}
%& \lightgray
& \color{Yellow} & \color{Yellow}\\
\mathsf{UMType} & \urho & ::=
%& \autype{\utau}
& \utau & \text{type annotation}\\
% &&
%& \aualltypes{\ut}{\urho}
% & \alltypes{\ut}{\urho} & \text{type parameterization}\\
&&
%& \auallmods{\usigma}{\uX}{\urho}
& \allmods{\uX}{\usigma}{\urho} & \text{module parameterization}\\
\mathsf{UMExp} & \uepsilon & ::=
%& \abindref{\tsmv}
& \tsmv & \text{TLM identifier reference}\\
% &&
%& \auabstype{\ut}{\uepsilon}
% & \abstype{\ut}{\uepsilon} & \text{type abstraction}\\
&&
%& \auabsmod{\usigma}{\uX}{\uepsilon}
& \absmod{\uX}{\usigma}{\uepsilon} & \text{module abstraction}\\
% &&
%& \auaptype{\utau}{\uepsilon}
% & \aptype{\uepsilon}{\utau} & \text{type application}\\
&&
%& \auapmod{\uM}{\uepsilon}
& \apmod{\uepsilon}{\uX} & \text{module application}\ECC
\end{array}
\]
\caption{Syntax of unexpanded TLM types and expressions in $\miniVerseParam$}
\label{fig:P-macro-expressions-types-u}
\end{figure}
\begin{figure}[t]
\[\begin{array}{lllllll}
\textbf{Sort} & & & \textbf{Operational Form}
%& \textbf{Stylized Form}
& \textbf{Description}\\
\LCC \color{Yellow}&\color{Yellow}& \color{Yellow}
%& \lightgray
& \color{Yellow} & \color{Yellow}\\
\mathsf{MType} & \rho & ::= & \aetype{\tau}
%& \tau
& \text{type annotation}\\
% &&& \aealltypes{t}{\rho}
%& \alltypes{t}{\rho}
% & \text{type parameterization}\\
&&& \aeallmods{\sigma}{X}{\rho}
%& \allmods{X}{\sigma}{\rho}
& \text{module parameterization}\\
\mathsf{MExp} & \epsilon & ::= & \adefref{a}
%& a
& \text{TLM definition reference}\\
% &&& \aeabstype{t}{\epsilon}
%& \abstype{t}{\epsilon}
% & \text{type abstraction}\\
&&& \aeabsmod{\sigma}{X}{\epsilon}
%& \absmod{X}{\sigma}{\epsilon}
& \text{module abstraction}\\
% &&& \aeaptype{\tau}{\epsilon}
%& \aptype{\epsilon}{\tau}
% & \text{type application}\\
&&& \aeapmod{M}{\epsilon}
%& \aptype{\epsilon}{M}
& \text{module application}\ECC
\end{array}\]
\caption[Syntax of TLM types and expressions in $\miniVerseParam$]{Syntax of TLM types and expressions in $\miniVerseParam$}
\label{fig:P-macro-expressions-types}
\end{figure}
\subsection{Syntax of the Unexpanded Language}
The syntax of the unexpanded language is defined in Figures \ref{fig:P-unexpanded-modules-signatures} through \ref{fig:P-macro-expressions-types}.
Each expanded form, with three exceptions, has a corresponding unexpanded form. We refer to these as the \emph{common forms}. The correspondence is defined in Appendix \ref{appendix:P-shared-forms}.
Kind variables, $k$, are one exception. Kind variables are used only in the metatheory.