Lectures onType Theory
Generative ML modules, matching, and sharing
appendix sectionrules

Generative ML modules, matching, and sharing

The reduced calculus uses one mixed context and the signatures σ::=B(u::κ;τ)Sigma(X:σ1).σ2Pi(X:σ1).σ2. Its singleton-kind delta is

Γc::Ty
ΓSing(c) kind
Sing-Kind
Γc::Ty
Γc::Sing(c)
Sing-I
Γc::Ty
ΓSing(c)kTy
Sing-Sub
Γd::Sing(c)
Γdc::Ty
Sing-E

Their formation rules are

Γκ kindΓ,u::κτ type
ΓB(u::κ;τ) sig
B-Sig
Γσ1 sigΓ,X:σ1σ2 sig
ΓSigma(X:σ1).σ2 sig
Sigma-Sig
Γσ1 sigΓ,X:σ1σ2 sig
ΓPi(X:σ1).σ2 sig
Pi-Sig

Signature equality is the congruence generated by inherited kind, constructor, and type equality:

Γκ1κ2 kindΓ,u::κ1τ1τ2 type
ΓB(u::κ1;τ1)B(u::κ2;τ2) sig
B-Eq
Γσ1σ1 sigΓ,X:σ1σ2σ2 sig
ΓSigma(X:σ1).σ2Sigma(X:σ1).σ2 sig
Sigma-Eq
Γσ1σ1 sigΓ,X:σ1σ2σ2 sig
ΓPi(X:σ1).σ2Pi(X:σ1).σ2 sig
Pi-Eq

The open module-value judgment is generated by

X:σΓ
ΓX mval
V-Var
Γv val
Γc;v mval
V-Basic
ΓV1 mvalΓV2 mval
ΓV1;V2 mval
V-Hierarchy
ΓλX:σ.M mval
V-Functor

Stable paths are generated by Q::=Xc;vQ1;Q2Q.1Q.2. Their complete projectibility rules are

X:σΓ
ΓX projectible
P-Var
Γv val
Γc;v projectible
P-Basic
ΓQ1 projectibleΓQ2 projectible
ΓQ1;Q2 projectible
P-Hierarchy
ΓQ projectible
ΓQ.i projectible
P-Projection

Seals, annotated lets, functor abstractions, and applications are not paths in the generative system.

The selected module typing family is

X:σΓ
ΓX:σ
Var
Γc::κΓe:τ[c/u]
Γc;e:B(u::Sing(c);τ)
Basic
ΓM:σ0D::Γσ0sσ
ΓMσ:σ
Seal
ΓM:σ1D::Γσ1sσ2
ΓM:σ2
Sub
Γσ sigΓM1:σ1Γ,X:σ1M2:σ
Γ(let X=M1 in M2):σ
Let
ΓM1:σ1ΓM2:σ2
ΓM1;M2:Sigma(:σ1).σ2
Hierarchy
ΓM:Sigma(X:σ1).σ2
ΓM.1:σ1
First
ΓM:Sigma(X:σ1).σ2XFV(σ2)
ΓM.2:σ2
Second
ΓQ projectibleΓQ:B(u::κ;τ)
ΓQ.s::κ
Static
ΓM:B(u::κ;τ)uFV(τ)
ΓM.d:τ
Dynamic
ΓQ:B(u::κ;τ)ΓQ projectible
ΓQ:B(u::Sing(Q.s);τ)
Self
ΓQ projectibleΓQ:Sigma(X:σ1).σ2ΓQ.1:σ1Γσ1sσ1
ΓQ:Sigma(X:σ1).σ2
Self-First
ΓQ projectibleΓQ:Sigma(:σ1).σ2ΓQ.2:σ2Γσ2sσ2
ΓQ:Sigma(:σ1).σ2
Self-Second
Γ,X:σ1M:σ2
ΓλX:σ1.M:Pi(X:σ1).σ2
Functor
ΓF:Pi(X:σ1).σ2ΓA:σ1XFV(σ2)
ΓF(A):σ2
Apply

Subkinding is k, dynamic-type subtyping is <:, and subsignature matching is s. Its structural rules are

Γσ sig
Γσsσ
Sig-Refl
Γσ1sσ2Γσ2sσ3
Γσ1sσ3
Sig-Trans
Γσ1σ1 sigΓσ1sσ2Γσ2σ2 sig
Γσ1sσ2
Sig-Convert

Its variance rules are

Γ,u::κ1τ1<:τ2Γκ1kκ2
ΓB(u::κ1;τ1)sB(u::κ2;τ2)
B-Match
Γσ1sσ1Γ,X:σ1σ2sσ2
ΓSigma(X:σ1).σ2sSigma(X:σ1).σ2
Sigma-Match
Γσ1sσ1Γ,X:σ1σ2sσ2
ΓPi(X:σ1).σ2sPi(X:σ1).σ2
Pi-Match

Operational module values are V::=c;vV1;V2λX:σ.M. Unlike the open judgment, this grammar has no variable case. Write hsubst(M;V;X) for substitution followed only by contraction of hierarchy projections exposed by substituting V, recursively along the original projection spine. It performs no seal, functor, or unrelated dynamic reduction. The sorted root contractions are VσDV,(c;v).dv,V1;V2.1V1,V1;V2.2V2,(let X=V in M):σhsubst(M;V;X),(λX:σ.M)(V)hsubst(M;V;X). The complete compatible-context family is

RR
EM[R]EM[R]
M-Context
MM
M.dM.d
D-Context
ee
c;ec;e
Basic-Context

Here EM::=[]EMσ(let X=EM in M):σEM;MV;EMEM.1EM.2EM(M)V(EM). No context crosses a functor or undischarged let body. Package elaboration is defined only for recursively elaboration-admissible derivations: every module-subderivation signature, every displayed matching endpoint, every opened signature, and the final result are closed-result. This includes the matching premises on Self-First and Self-Second. Matching nodes insert mcoeD; module bindings first bind the translated computation to a fresh target variable and then apply Openσ, so no module computation is duplicated and no existential witness escapes. Rule Self repacks the unchanged witness at its singleton kind. Rules Self-First and Self-Second retranslate the refined component and pair it with the unchanged translated component; projectibility ensures that this duplication allocates no generative name.

The proof-relevant phase card imports no further rule into MLMod0. Its comparison uses ModTT dependent products over dynamic signatures, rather than adding an object-language arrow. The imported endpoint has closed families σ,τ:Val(type)Sig, an α-small relation family on pairs of closed values, and the function of phase-separated sets stated in theorem 14.32.

Search the book

Type to search the local edition.