Lectures onType Theory
Strict data rows and qualified row inference
appendix sectionrules

Strict data rows and qualified row inference

The two-sorted grammar is τ::=αNatBoolStringττRec(ρ)Var(ρ),ρ::=ξϵρ{:τρ}. A lacks predicate is ρ\. Normalize it by ϵρ\,{m:τρ}\ρ\(m),{:τρ}\,ξ\ξ\. Predicate contexts are normalized finite sets of residual variable predicates. Entailment and strict row formation are

ξ\P
Pξ\
L-Assume
Pϵρ\
L-Empty
Pρ\m
P{m:τρ}\
L-Extend
Pξ row
Row-Var
Pϵρ row
Row-Empty
Pρ rowPτ typePρ\
P{:τρ} row
Row-Ext

Type formation is

Pτ typePυ type
Pτυ type
Ty-Arrow
Pρ row
PRec(ρ) type
Ty-Record
Pρ row
PVar(ρ) type
Ty-Variant

The type-variable and three base-type cases are axioms. Row equality exchanges adjacent distinct labels only; aPa additionally requires both sides formed under P. An admissible substitution S:PQ is sorted, has Q-formed images, normalizes P[S], and satisfies Qnf(P[S]).

Qualified schemes are χ::=Pτ,σ::=α¯ξ¯.Pτ. For X=ftv(P,τ)ftv(Γ),Pg={pPftv(p)X},Pr=PPg, put GenΓ(Pτ)=X.Pτ. Qualified typing is

Γ(x)=α¯ξ¯.Qτ0Pnf(Q[T])Pτ0[T] type
Γqx:Pτ0[T]
Q-Var
c:α¯ξ¯.Qτ0Σ0Pnf(Q[T])Pτ0[T] type
Γqc:Pτ0[T]
Q-Const
Γ,x:τ1qe:Pτ2
Γqλx.e:Pτ1τ2
Q-Lam
Γqe1:P1τ1τ2Γqe2:P2τ1nf(P1P2)=P
Γqe1e2:Pτ2
Q-App
Γqe1:P1τ1Γ,x:GenΓ(P1τ1)qe2:P2τ2nf(P1rP2)=P
Γqlet x=e1 in e2:Pτ2
Q-Let
Γqe:PττPτ
Γqe:Pτ
Q-Conv

The saturated record and variant terms add e::={}{=ee}e.e=eembedecasee of {=xe1;ye2}. Their complete typing rules are

Γq{}:Rec(ϵρ)
Q-Empty
Γqr:PRec({:τρ})
Γqr.:Pτ
Q-Select
Γqr:PRec({:τρ})
Γqr:PRec(ρ)
Q-Restrict
Γqa:P1τΓqr:P2Rec(ρ)nf(P1P2{ρ\})=P
Γq{=ar}:PRec({:τρ})
Q-Extend
Γqa:P0τnf(P0{ρ\})=P
Γq=a:PVar({:τρ})
Q-Inject
Γqu:P0Var(ρ)nf(P0{ρ\})=P
Γqembedu:PVar({:τρ})
Q-Embed
Γqu:P0Var({:τρ})Γ,x:τqe1:P1υΓ,y:Var(ρ)qe2:P2υnf(P0P1P2)=P
Γqcaseu of {=xe1;ye2}:Pυ
Q-Case

Values and the complete source evaluation contexts are v::=cλx.eRV,R::={}{=vR},V::==v,E::=[]EevElet x=E in e{=Ee}{=vE}E.E=EembedEcaseE of {=xe1;ye2}. Besides beta and let, the primitive roots are {=vR}.v,{m=wR}.R.(m),{=vR}R,{m=wR}{m=wR}(m),embedm=vm=v(m), together with matching case reduction to e1[v/x] and unequal-tag case reduction to e2[m=v/y]. Compatibility is EeEe.

Constrained insertion and solving have judgments insertP(:τ,ρ)=(I,Q,ρ),solve(P;E)=(U,Q), and are mutually recursive. Insertion has four clauses: an open tail ξ is replaced by {:τζ}, adding ζ\; empty fails; a matching head solves its field-type equation; and a distinct head recurses on the tail and is reattached. Every fresh tail is global to the run.

The solver normalizes P before every call, uses the empty and reflexive clauses first, then sorted variable elimination with occurs check, orientation, rigid type decomposition, empty-row cases, and finally row-extension exposure. The last clause is exactly insertP(:τ,q)=(I,P1,q)solve(P1;(ρ[I]q,E[I]))=(V,Q)solve(P;({:τρ}q,E))=(I;V,Q). These clauses are tried in this order, and rigid subequations are prepended left to right. A variable–variable equation eliminates the left variable; the symmetric orientation is used only when the left side is not a variable.

Qualified W returns Wr(Γ,e)=(P,S,τ). Its variable, constant, lambda, application, and let clauses are the HM clauses with qualified instantiation, normalized predicate unions, solver calls, and the residual P1r retained at let. The exact new clauses are: empty returns (,id,Rec(ϵρ)); extension infers payload then record and solves the record shape with a fresh tail lacking ; selection and restriction solve against Rec({:αξ}); injection introduces a fresh tail and its lacks predicate; embedding solves the old variant row and leaves the new payload type fresh; case solves the scrutinee shape, infers the matching branch, then the residual branch under all prior substitutions, and finally solves the branch-result equation. Its returned case substitution is S0;U0;S1;S2;V, in that order. These are precisely the clauses of definition 4.29; no effect-row equation is admitted here.

With a fixed total label order, lacks evidence is

dξ,:ξ\Δ
Δdξ,:ξ\
Ev-Assume
Δ0:ϵρ\
Ev-Empty
Δd:ρ\<m
Δd:{m:τρ}\
Ev-Before
Δd:ρ\m<
Δd+1:{m:τρ}\
Ev-After

The named syntax translation on row types is lay(ξ)=ξ,lay(ϵρ)=ϵρ,lay({:τρ})=sort({:lay(τ)lay(ρ)}),lay(Rec(ρ))=Array(lay(ρ)),lay(Var(ρ))=Sum(lay(ρ)),lay(τυ)=lay(τ)lay(υ). Let canTy recursively sort every strict row index. Target type conversion is explicit:

Δ;Γt:θcanTy(θ)=canTy(θ)
Δ;Γt:θ
T-Conv

Target schemes are X.Off(P)θ, with explicit static instantiation and evidence abstraction:

Γ(x)=σ
Δ;Γx:σ
T-Var
c:θΣ0
Δ;Γc:θ
T-Const
Δ;Γt:X.Off(P)θT sorted and formedΔd¯:Off(P[T])
Δ;Γt[T]d¯:θ[T]
T-Inst
Δ,d¯:Off(P);Γt:θXftv(Δ,Γ)=
Δ;ΓΛX.λd¯.t:X.Off(P)θ
T-Ev-Abs
Δ;Γt1:σΔ;Γ,x:σt2:θ
Δ;Γlet x=t1 in t2:θ
T-Let

Writing a monotype as the corresponding empty scheme, the ordinary target rules are

Γ(x)=θ
Δ;Γx:θ
T-MVar
c:θΣ0
Δ;Γc:θ
T-MConst
Δ;Γ,x:θt:υ
Δ;Γλx.t:θυ
T-Lam
Δ;Γt:θυΔ;Γu:θ
Δ;Γtu:υ
T-App

The nullary array rule and six saturated evidence-carrying data rules are

Δ;Γ[]:Array(ϵρ)
T-Empty
Δd:ρ\Δ;Γr:Array({:αρ})
Δ;Γlookup d r:α
T-Lookup
Δd:ρ\Δ;Γr:Array({:αρ})
Δ;Γdelete d r:Array(ρ)
T-Delete
Δd:ρ\Δ;Γa:αΔ;Γr:Array(ρ)
Δ;Γinsert d a r:Array({:αρ})
T-Insert
Δd:ρ\Δ;Γa:α
Δ;Γtag d a:Sum({:αρ})
T-Tag
Δd:ρ\Δ;Γu:Sum(ρ)
Δ;Γwiden d u:Sum({:αρ})
T-Widen
Δd:ρ\Δ;Γu:Sum({:αρ})Δ;Γf:αβΔ;Γg:Sum(ρ)β
Δ;Γsplit d u f g:β
T-Split

The target reductions use evidence as zero-based array/tag offsets and are the lookup, delete, insert, tag, widen, and split roots displayed in definition 7.51. Evidence-passing compilation accepts a principal result only when ftv(P)ftv(Γ,τ); this unambiguity side condition is part of the compiler interface, not the source typing judgment.

Search the book

Type to search the local edition.