1
\chapter[The Module System]{The Module System\label{chapter:Modules}}
3
The module system extends the Calculus of Inductive Constructions
4
providing a convenient way to structure large developments as well as
5
a mean of massive abstraction.
6
%It is described in details in Judicael's thesis and Jacek's thesis
8
\section{Modules and module types}
10
\paragraph{Access path.} It is denoted by $p$, it can be either a module
11
variable $X$ or, if $p'$ is an access path and $id$ an identifier, then
12
$p'.id$ is an access path.
14
\paragraph{Structure element.} It is denoted by \elem\ and is either a
15
definition of a constant, an assumption, a definition of an inductive,
16
a definition of a module, an alias of module or a module type abbreviation.
18
\paragraph{Structure expression.} It is denoted by $S$ and can be:
20
\item an access path $p$
21
\item a plain structure $\struct{\nelist{\elem}{;}}$
22
\item a functor $\functor{X}{S}{S'}$, where $X$ is a module variable,
23
$S$ and $S'$ are structure expression
24
\item an application $S\,p$, where $S$ is a structure expression and $p$
26
\item a refined structure $\with{S}{p}{p'}$ or $\with{S}{p}{t:T}$ where $S$
27
is a structure expression, $p$ and $p'$ are access paths, $t$ is a term
28
and $T$ is the type of $t$.
30
The symbol $W$ will be used to denote a plain structure or a functor.
31
\paragraph{Module definition,} is written $\Mod{X}{S}{S'}$ and
32
consists of a module variable $X$, a module type
33
$S$ which can be any structure expression and optionally a module implementation $S'$
34
which can be any structure expression except a refined structure.
36
\paragraph{Module alias,} is written $\ModA{X}{p}$ and
37
consists of a module variable $X$ and a module path $p$.
39
\paragraph{Module type abbreviation,} is written $\ModType{Y}{S}$, where
40
$Y$ is an identifier and $S$ is any structure expression .
43
\section{Typing Modules}
45
In order to introduce the typing system we first slightly extend
46
the syntactic class of terms and environments given in
47
section~\ref{Terms}. The environments, apart from definitions of
48
constants and inductive types now also hold any other structure elements.
49
Terms, apart from variables, constants and complex terms,
50
include also access paths.
52
We also need additional typing judgments:
54
\item \WFT{E}{S}, denoting that a structure $S$ is well-formed,
56
\item \WTM{E}{p}{S}, denoting that the module pointed by $p$ has type $S$ in
59
\item \WEV{E}{S}{W}, denoting that a structure $S$ is evaluated to
60
a structure $W$ in weak head normal form.
62
\item \WS{E}{S_1}{S_2}, denoting that a structure $S_1$ is a subtype of a
65
\item \WS{E}{\elem_1}{\elem_2}, denoting that a structure element
66
$\elem_1$ is more precise that a structure element $\elem_2$.
68
The rules for forming structures are the following:
74
}{%%%%%%%%%%%%%%%%%%%%%
81
\WEV{E;\ModS{X}{S}}{S'}{W}\qquad\WFT{E;\ModS{X}{S}}{W}
82
}{%%%%%%%%%%%%%%%%%%%%%%%%%%
83
\WFT{E}{\functor{X}{S}{S'}}
87
Evaluation of structures to weak head normal form:
93
\WEV{E}{S}{\functor{X}{S_1}{S_2}}~~~~~\WEV{E}{S_1}{W_1}\\
94
\WTM{E}{p}{W_3}\qquad \WS{E}{W_3}{W_1}
96
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97
\WEV{E}{S\,p}{S_2\{p/X,t_1/p_1.c_1,\ldots,t_n/p_n.c_n\}}
101
In the last rule, $\{t_1/p_1.c_1,\ldots,t_n/p_n.c_n\}$ is the resulting
102
substitution from the inlining mechanism. We substitute in $S$ the
103
inlined fields $p_i.c_i$ form $\ModS{X}{S_1}$ by the corresponding delta-reduced term $t_i$ in~$p$.
105
\item[WEVAL-WITH-MOD]
109
\WEV{E}{S}{\structe{\ModS{X}{S_1}}}~~~~~\WEV{E;\elem_1;\ldots;\elem_{i-1}}{S_1}{W_1}\\
110
\WTM{E}{p}{W_2}\qquad \WS{E;\elem_1;\ldots;\elem_{i-1}}{W_2}{W_1}
112
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114
\WEVT{E}{\with{S}{x}{p}}{\structes{\ModA{X_1}{p}}{p/X}}
118
\item[WEVAL-WITH-MOD-REC]
122
\WEV{E}{S}{\structe{\ModS{X_1}{S_1}}}\\
123
\WEV{E;\elem_1;\ldots;\elem_{i-1}}{\with{S_1}{p}{p_1}}{W_1}
125
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
\WEVT{E}{\with{S}{X_1.p}{p_1}}{\structes{\ModS{X_1}{W_1}}{p_1/X_1.p}}
131
\item[WEVAL-WITH-DEF]
135
\WEV{E}{S}{\structe{\Assum{}{c}{T_1}}}\\
136
\WS{E;\elem_1;\ldots;\elem_{i-1}}{\Def{}{c}{t}{T}}{\Assum{}{c}{T_1}}
138
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140
\WEVT{E}{\with{S}{c}{t:T}}{\structe{\Def{}{c}{t}{T}}}
144
\item[WEVAL-WITH-DEF-REC]
148
\WEV{E}{S}{\structe{\ModS{X_1}{S_1}}}\\
149
\WEV{E;\elem_1;\ldots;\elem_{i_1}}{\with{S_1}{p}{p_1}}{W_1}
151
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153
\WEVT{E}{\with{S}{X_1.p}{t:T}}{\structe{\ModS{X}{W_1}}}
158
\item[WEVAL-PATH-MOD]
162
\WEV{E}{p}{\structe{ \Mod{X}{S}{S_1}}}\\
163
\WEV{E;\elem_1;\ldots;\elem_{i-1}}{S}{W}
165
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172
\WF{E}{}~~~~~~\Mod{X}{S}{S_1}\in E\\
175
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179
\item[WEVAL-PATH-ALIAS]
183
\WEV{E}{p}{\structe{\ModA{X}{p_1}}}\\
184
\WEV{E;\elem_1;\ldots;\elem_{i-1}}{p_1}{W}
186
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193
\WF{E}{}~~~~~~~\ModA{X}{p_1}\in E\\
196
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200
\item[WEVAL-PATH-TYPE]
204
\WEV{E}{p}{\structe{\ModType{Y}{S}}}\\
205
\WEV{E;\elem_1;\ldots;\elem_{i-1}}{S}{W}
207
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211
\item[WEVAL-PATH-TYPE]
215
\WF{E}{}~~~~~~~\ModType{Y}{S}\in E\\
218
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223
Rules for typing module:
229
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235
The last rule, called strengthening is used to make all module fields
236
manifestly equal to themselves. The notation $W/p$ has the following
239
\item if $W\lra\struct{\elem_1;\dots;\elem_n}$ then
240
$W/p=\struct{\elem_1/p;\dots;\elem_n/p}$ where $\elem/p$ is defined as
243
\item $\Def{}{c}{t}{T}/p\footnote{Opaque definitions are processed as assumptions.} ~=~ \Def{}{c}{t}{T}$
244
\item $\Assum{}{c}{U}/p ~=~ \Def{}{c}{p.c}{U}$
245
\item $\ModS{X}{S}/p ~=~ \ModA{X}{p.X}$
246
\item $\ModA{X}{p'}/p ~=~ \ModA{X}{p'}$
247
\item $\Ind{}{\Gamma_P}{\Gamma_C}{\Gamma_I}/p ~=~ \Indp{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p}$
248
\item $\Indpstr{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p'}{p} ~=~ \Indp{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p'}$
250
\item if $W\lra\functor{X}{S'}{S''}$ then $W/p=W$
252
The notation $\Indp{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p}$ denotes an
253
inductive definition that is definitionally equal to the inductive
254
definition in the module denoted by the path $p$. All rules which have
255
$\Ind{}{\Gamma_P}{\Gamma_C}{\Gamma_I}$ as premises are also valid for
256
$\Indp{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p}$. We give the formation rule
257
for $\Indp{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p}$ below as well as
258
the equality rules on inductive types and constructors. \\
260
The module subtyping rules:
266
\WS{E;\elem_1;\dots;\elem_n}{\elem_{\sigma(i)}}{\elem'_i}
267
\textrm{ \ for } i=1..m \\
268
\sigma : \{1\dots m\} \ra \{1\dots n\} \textrm{ \ injective}
271
\WS{E}{\struct{\elem_1;\dots;\elem_n}}{\struct{\elem'_1;\dots;\elem'_m}}
275
\inference{% T_1 -> T_2 <: T_1' -> T_2'
278
\WEV{E}{S_1}{W_1}\qquad\WEV{E}{S_1'}{W_1'}\\
279
\WEV{E;\ModS{X}{S_1}}{S_2}{W_2}\qquad \WEV{E;\ModS{X}{S_1'}}{S_2'}{W_2'}\\
280
\WS{E}{W_1'}{W_1}~~~~~~~~~~\WS{E;\ModS{X}{S_1'}}{W_2}{W_2'}
282
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
283
\WS{E}{\functor{X}{S_1}{S_2}}{\functor{X}{S_1'}{S_2'}}
286
% these are derived rules
290
% \WS{E}{T_1}{T_2}~~~~~~~~~~\WTERED{}{T_1}{=}{T_1'}~~~~~~~~~~\WTERED{}{T_2}{=}{T_2'}
291
% }{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304
Structure element subtyping rules:
309
\WTELECONV{}{T_1}{T_2}
311
\WSE{\Assum{}{c}{T_1}}{\Assum{}{c}{T_2}}
317
\WTELECONV{}{T_1}{T_2}
319
\WSE{\Def{}{c}{t}{T_1}}{\Assum{}{c}{T_2}}
325
\WTELECONV{}{T_1}{T_2}~~~~~~~~\WTECONV{}{c}{t_2}
327
\WSE{\Assum{}{c}{T_1}}{\Def{}{c}{t_2}{T_2}}
333
\WTELECONV{}{T_1}{T_2}~~~~~~~~\WTECONV{}{t_1}{t_2}
335
\WSE{\Def{}{c}{t_1}{T_1}}{\Def{}{c}{t_2}{T_2}}
341
\WTECONV{}{\Gamma_P}{\Gamma_P'}%
342
~~~~~~~~\WTECONV{\Gamma_P}{\Gamma_C}{\Gamma_C'}%
343
~~~~~~~~\WTECONV{\Gamma_P;\Gamma_C}{\Gamma_I}{\Gamma_I'}%
345
\WSE{\Ind{}{\Gamma_P}{\Gamma_C}{\Gamma_I}}%
346
{\Ind{}{\Gamma_P'}{\Gamma_C'}{\Gamma_I'}}
352
\WTECONV{}{\Gamma_P}{\Gamma_P'}%
353
~~~~~~~~\WTECONV{\Gamma_P}{\Gamma_C}{\Gamma_C'}%
354
~~~~~~~~\WTECONV{\Gamma_P;\Gamma_C}{\Gamma_I}{\Gamma_I'}%
356
\WSE{\Indp{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p}}%
357
{\Ind{}{\Gamma_P'}{\Gamma_C'}{\Gamma_I'}}
363
\WTECONV{}{\Gamma_P}{\Gamma_P'}%
364
~~~~~~\WTECONV{\Gamma_P}{\Gamma_C}{\Gamma_C'}%
365
~~~~~~\WTECONV{\Gamma_P;\Gamma_C}{\Gamma_I}{\Gamma_I'}%
366
~~~~~~\WTECONV{}{p}{p'}
368
\WSE{\Indp{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p}}%
369
{\Indp{}{\Gamma_P'}{\Gamma_C'}{\Gamma_I'}{p'}}
372
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
378
\WSE{\ModS{X}{S_1}}{\ModS{X}{S_2}}
384
\WTM{E}{p}{S_1}~~~~~~~~\WSE{S_1}{S_2}
386
\WSE{\ModA{X}{p}}{\ModS{X}{S_2}}
392
\WTM{E}{p}{S_2}~~~~~~~~
393
\WSE{S_1}{S_2}~~~~~~~~\WTECONV{}{X}{p}
395
\WSE{\ModS{X}{S_1}}{\ModA{X}{p}}
403
\WSE{\ModA{X}{p_1}}{\ModA{X}{p_2}}
406
\item[MODTYPE-MODTYPE]
409
\WSE{S_1}{S_2}~~~~~~~~\WSE{S_2}{S_1}
411
\WSE{\ModType{Y}{S_1}}{\ModType{Y}{S_2}}
415
New environment formation rules
420
\WF{E}{}~~~~~~~~\WFT{E}{S}
430
\WF{E}{}~~~~~\WFT{E}{S_1}~~~~~\WFT{E}{S_2}
433
\WF{E;\Mod{X}{S_1}{S_2}}{}
440
\WF{E}{}~~~~~~~~~~~\WTE{}{p}{S}
448
\WF{E}{}~~~~~~~~~~~\WFT{E}{S}
450
\WF{E,\ModType{Y}{S}}{}
457
\WF{E;\Ind{}{\Gamma_P}{\Gamma_C}{\Gamma_I}}{}\\
458
\WT{E}{}{p:\struct{\elem_1;\dots;\elem_i;\Ind{}{\Gamma_P'}{\Gamma_C'}{\Gamma_I'};\dots}}\\
459
\WS{E}{\Ind{}{\Gamma_P'}{\Gamma_C'}{\Gamma_I'}}{\Ind{}{\Gamma_P}{\Gamma_C}{\Gamma_I}}
461
}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462
\WF{E;\Indp{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p}}{}
466
Component access rules
471
\WTEG{p}{\struct{\elem_1;\dots;\elem_i;\Assum{}{c}{T};\dots}}
479
\WTEG{p}{\struct{\elem_1;\dots;\elem_i;\Def{}{c}{t}{T};\dots}}
485
Notice that the following rule extends the delta rule defined in
489
\WTEG{p}{\struct{\elem_1;\dots;\elem_i;\Def{}{c}{t}{U};\dots}}
491
\WTEGRED{p.c}{\triangleright_\delta}{t}
495
In the rules below we assume $\Gamma_P$ is $[p_1:P_1;\ldots;p_r:P_r]$,
496
$\Gamma_I$ is $[I_1:A_1;\ldots;I_k:A_k]$, and $\Gamma_C$ is
497
$[c_1:C_1;\ldots;c_n:C_n]$
501
\WTEG{p}{\struct{\elem_1;\dots;\elem_i;\Ind{}{\Gamma_P}{\Gamma_C}{\Gamma_I};\dots}}
503
\WTEG{p.I_j}{(p_1:P_1)\ldots(p_r:P_r)A_j}
508
\WTEG{p}{\struct{\elem_1;\dots;\elem_i;\Ind{}{\Gamma_P}{\Gamma_C}{\Gamma_I};\dots}}
510
\WTEG{p.c_m}{(p_1:P_1)\ldots(p_r:P_r){C_m}{I_j}{(I_j~p_1\ldots
517
\WT{E}{}{p}{\struct{\elem_1;\dots;\elem_i;\Indp{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p'};\dots}}
519
\WTRED{E}{}{p.I_i}{\triangleright_\delta}{p'.I_i}
524
\WT{E}{}{p}{\struct{\elem_1;\dots;\elem_i;\Indp{}{\Gamma_P}{\Gamma_C}{\Gamma_I}{p'};\dots}}
526
\WTRED{E}{}{p.c_i}{\triangleright_\delta}{p'.c_i}
532
% %%% replaced by \triangle_\delta
533
% Module path equality is a transitive and reflexive closure of the
534
% relation generated by ACC-MODEQ and ENV-MODEQ.
544
% \item []MP-EQ-TRANS
547
% \WTEGRED{p}{=}{p'}~~~~~~\WTEGRED{p'}{=}{p''}
549
% \WTEGRED{p'}{=}{p''}
556
% $Id: RefMan-modr.tex 11246 2008-07-22 15:10:05Z soubiran $
560
%%% TeX-master: "Reference-Manual"