Previous Up Next

Chapter 5  The Module System

The module system extends the Calculus of Inductive Constructions providing a convenient way to structure large developments as well as a mean of massive abstraction.

5.1  Modules and module types

Access path.
It is denoted by p, it can be either a module variable X or, if p' is an access path and id an identifier, then p'.id is an access path.

Structure element.
It is denoted by Impl and is either a definition of a constant, an assumption, a definition of an inductive or a definition of a module or a module type abbreviation.

Module expression.
It is denoted by M and can be:
Signature element.
It is denoted by Spec, it is a specification of a constant, an assumption, an inductive, a module or a module type abbreviation.

Module type,
denoted by T can be:
Module definition,
written Mod(X:T:=M) can be a structure element. It consists of a module variable X, a module type T and a module expression M.

Module specification,
written ModS(X:T) or ModSEq(X:T==p) can be a signature element or a part of an environment. It consists of a module variable X, a module type T and, optionally, a module path p.

Module type abbreviation,
written ModType(S:=T), where S is a module type name and T is a module type.

5.2  Typing Modules

In order to introduce the typing system we first slightly extend the syntactic class of terms and environments given in section 4.1. The environments, apart from definitions of constants and inductive types now also hold any other signature elements. Terms, apart from variables, constants and complex terms, include also access paths.

We also need additional typing judgments: The rules for forming module types are the following:
WF-SIG
WF(E;E')[]
E[] |- WF( Sig E End)
WF-FUN
E; ModS(X:T)[] |- WF(T')
E[] |- WF( Funsig(X:TT')
Rules for typing module expressions:
MT-STRUCT
E[] |- WF( Sig Spec1;...;Specn  End)
E;Spec1;...;Speci-1[] |- Impli : Speci for i=1... n
E[] |- Struct Impl1;...;Impln  End : Sig Spec1;...;Specn  End
MT-FUN
E; ModS(X:T)[] |- M : T'
E[] |- Functor(X:TM : Funsig(X:TT'
MT-APP
E[] |- p : Funsig(X1:T1) ... Funsig(Xn:TnT'
E[] |- pi : Ti{X1/p1... Xi-1/pi-1} for i=1... n
E[] |- p  p1 ... pn : T'{X1/p1... Xn/pn}
MT-SUB
E[] |- M : T            E[] |- T <: T'
E[] |- M : T'
MT-STR
E[] |- p : T
E[] |- p : T/p
The last rule, called strengthening is used to make all module fields manifestly equal to themselves. The notation T/p has the following meaning: The notation Indp()[GammaP](
GammaC:=GammaI  )
denotes an inductive definition that is definitionally equal to the inductive definition in the module denoted by the path p. All rules which have Ind()[GammaP](GammaC:=GammaI ) as premises are also valid for Indp()[GammaP](
GammaC:=GammaI  )
. We give the formation rule for Indp()[GammaP](
GammaC:=GammaI  )
below as well as the equality rules on inductive types and constructors.

The module subtyping rules:
MSUB-SIG
E;Spec1;...;Specn[] |- Specsigma(i) <: Spec'i for i=1..m
sigma : {1... m} -> {1... n} injective
E[] |- Sig Spec1;...;Specn  End <: Sig Spec'1;...;Spec'm  End
MSUB-FUN
E[] |- T1' <: T1          E; ModS(X:T1')[] |- T2 <: T2'
E[] |- Funsig(X:T1T2 <: Funsig(X:T1') T2'
Specification subtyping rules:
ASSUM-ASSUM
E[] |- U1 <=betadeltaiotazeta U2
E[] |- Assum()(c:U1) <: Assum()(c:U2)
DEF-ASSUM
E[] |- U1 <=betadeltaiotazeta U2
E[] |- Def()(c:=t:U1) <: Assum()(c:U2)
ASSUM-DEF
E[] |- U1 <=betadeltaiotazeta U2        E[] |- c =betadeltaiotazeta t2
E[] |- Assum()(c:U1) <: Def()(c:=t2:U2)
DEF-DEF
E[] |- U1 <=betadeltaiotazeta U2        E[] |- t1 =betadeltaiotazeta t2
E[] |- Def()(c:=t1:U1) <: Def()(c:=t2:U2)
IND-IND
E[] |- GammaP =betadeltaiotazeta GammaP'        E[GammaP] |- GammaC =betadeltaiotazeta GammaC'        E[GammaP;GammaC] |- GammaI =betadeltaiotazeta GammaI'
E[] |- Ind()[GammaP](GammaC:=GammaI ) <: Ind()[GammaP'](GammaC':=GammaI' )
INDP-IND
E[] |- GammaP =betadeltaiotazeta GammaP'        E[GammaP] |- GammaC =betadeltaiotazeta GammaC'        E[GammaP;GammaC] |- GammaI =betadeltaiotazeta GammaI'
E[] |- Indp()[GammaP](
GammaC:=GammaI  )
<: Ind()[GammaP'](GammaC':=GammaI' )
INDP-INDP
E[] |- GammaP =betadeltaiotazeta GammaP'      E[GammaP] |- GammaC =betadeltaiotazeta GammaC'      E[GammaP;GammaC] |- GammaI =betadeltaiotazeta GammaI'      E[] |- p =betadeltaiotazeta p'
E[] |- Indp()[GammaP](
GammaC:=GammaI  )
<: Indp'()[GammaP'](
GammaC':=GammaI'  )
MODS-MODS
E[] |- T1 <: T2
E[] |- ModS(m:T1) <: ModS(m:T2)
MODEQ-MODS
E[] |- T1 <: T2
E[] |- ModSEq(m:T1==p) <: ModS(m:T2)
MODS-MODEQ
E[] |- T1 <: T2        E[] |- m =betadeltaiotazeta p2
E[] |- ModS(m:T1) <: ModSEq(m:T2==p2)
MODEQ-MODEQ
E[] |- T1 <: T2        E[] |- p1 =betadeltaiotazeta p2
E[] |- ModSEq(m:T1==p1) <: ModSEq(m:T2==p2)
MODTYPE-MODTYPE
E[] |- T1 <: T2        E[] |- T2 <: T1
E[] |- ModType(S:=T1) <: ModType(S:=T2)
Verification of the specification
IMPL-SPEC
WF(E;Spec)[]
Spec is one of Def, Assum, Ind, ModType
E[] |- Spec : Spec
MOD-MODS
WF(E; ModS(m:T))[]        E[] |- M : T
E[] |- Mod(m:T:=M) : ModS(m:T)
MOD-MODEQ
WF(E; ModSEq(m:T==p))[]           E[] |- p =betadeltaiotazeta p'
E[] |- Mod(m:T:=p') : ModSEq(m:T==p')
New environment formation rules
WF-MODS
WF(E)[]        E[] |- WF(T)
WF(E; ModS(m:T))[]
WF-MODEQ
WF(E)[]           E[] |- p : T
WF(E, ModSEq(m:T==p))[]
WF-MODTYPE
WF(E)[]           E[] |- WF(T)
WF(E, ModType(S:=T))[]
WF-IND
WF(E;Ind()[GammaP](GammaC:=GammaI ))[]
E[] |- p: Sig Spec1;...;Specn;Ind()[GammaP'](GammaC':=GammaI' );...  End :
E[] |- Ind()[GammaP'](GammaC':=GammaI' ){p.l/l}l in labels(Spec1;...;Specn) <: Ind()[GammaP](GammaC:=GammaI )
WF(E; Indp()[GammaP](
GammaC:=GammaI  )
)[]
Component access rules
ACC-TYPE
E[Gamma] |- p : Sig Spec1;...;Speci;Assum()(c:U);...  End
E[Gamma] |- p.c : U{p.l/l}l in labels(Spec1;...;Speci)

E[Gamma] |- p : Sig Spec1;...;Speci;Def()(c:=t:U);...  End
E[Gamma] |- p.c : U{p.l/l}l in labels(Spec1;...;Speci)
ACC-DELTA
Notice that the following rule extends the delta rule defined in section 4.3
E[Gamma] |- p : Sig Spec1;...;Speci;Def()(c:=t:U);...  End
E[Gamma] |- p.c |>delta t{p.l/l}l in labels(Spec1;...;Speci)

In the rules below we assume GammaP is [p1:P1;...;pr:Pr], GammaI is [I1:A1;...;Ik:Ak], and GammaC is [c1:C1;...;cn:Cn]
ACC-IND
E[Gamma] |- p : Sig Spec1;...;Speci;Ind()[GammaP](GammaC:=GammaI );...  End
E[Gamma] |- p.Ij : (p1:P1)...(pr:Pr)Aj{p.l/l}l in labels(Spec1;...;Speci)
E[Gamma] |- p : Sig Spec1;...;Speci;Ind()[GammaP](GammaC:=GammaI );...  End
E[Gamma] |- p.cm : (p1:P1)...(pr:Pr)Cm{Ij/(Ij p1... pr)}j=1... k{p.l/l}l in labels(Spec1;...;Speci)
ACC-INDP
E[] |- p : Sig Spec1;...;Specn; Indp'()[GammaP](
GammaC:=GammaI  )
;...  End
E[] |- p.Ii |>delta p'.Ii
E[] |- p : Sig Spec1;...;Specn; Indp'()[GammaP](
GammaC:=GammaI  )
;...  End
E[] |- p.ci |>delta p'.ci
ACC-MOD
E[Gamma] |- p : Sig Spec1;...;Speci; ModS(m:T);...  End
E[Gamma] |- p.m : T{p.l/l}l in labels(Spec1;...;Speci)

E[Gamma] |- p : Sig Spec1;...;Speci; ModSEq(m:T==p');...  End
E[Gamma] |- p.m : T{p.l/l}l in labels(Spec1;...;Speci)
ACC-MODEQ
E[Gamma] |- p : Sig Spec1;...;Speci; ModSEq(m:T==p');...  End
E[Gamma] |- p.m |>delta p'{p.l/l}l in labels(Spec1;...;Speci)
ACC-MODTYPE
E[Gamma] |- p : Sig Spec1;...;Speci; ModType(S:=T);...  End
E[Gamma] |- p.S |>delta T{p.l/l}l in labels(Spec1;...;Speci)
The function labels() is used to calculate the set of label of the set of specifications. It is defined by labels(Spec1;...;Specn)=labels(Spec1)union...;unionlabels(Specn) where labels(Spec) is defined as follows: Environment access for modules and module types
ENV-MOD
WF(E; ModS(m:T);E')[Gamma]
E; ModS(m:T);E'[Gamma] |- m : T
WF(E; ModSEq(m:T==p);E')[Gamma]
E; ModSEq(m:T==p);E'[Gamma] |- m : T
ENV-MODEQ
WF(E; ModSEq(m:T==p);E')[Gamma]
E; ModSEq(m:T==p);E'[Gamma] |- m |>delta p
ENV-MODTYPE
WF(E; ModType(S:=T);E')[Gamma]
E; ModType(S:=T);E'[Gamma] |- S |>delta T
ENV-INDP
WF(E; Indp()[GammaP](
GammaC:=GammaI  )
)[]
E;Indp()[GammaP](
GammaC:=GammaI  )
[] |- Ii |>delta p.Ii
WF(E; Indp()[GammaP](
GammaC:=GammaI  )
)[]
E;Indp()[GammaP](
GammaC:=GammaI  )
[] |- ci |>delta p.ci

Previous Up Next