Lectures onType Theory
Gradual source and ground-cast target
appendix sectionrules

Gradual source and ground-cast target

The source and target of chapter 11 share A,B::=2N?AB,G::=2N??. For every A?, the ground-shape operation used below is gnd(2)=2,gnd(N)=N,gnd(AB)=??. Consistency is the least relation generated by

?cA
C-UnkL
Ac?
C-UnkR
2c2
C-Bool
NcN
C-Nat
A1cB1A2cB2
A1A2cB1B2
C-Arr

Function matching is the partial operation fun(AB)=AB and fun(?)=??. For e::=bnxλx:A.e(e1e2), the complete source table is

Γb:2
G-Bool
Γn:N
G-Nat
x:AΓ
Γx:A
G-Var
Γ,x:Ae:B
Γλx:A.e:AB
G-Lam
Γe1:Cfun(C)=ABΓe2:DDcA
Γ(e1e2):B
G-App

Target terms and blame-label complementation are a::=bnxλx:A.aa1a2BApablamep,p¯=p. Their complete typing table is

ΓCb:2
T-Bool
ΓCn:N
T-Nat
x:AΓ
ΓCx:A
T-Var
Γ,x:ACa:B
ΓCλx:A.a:AB
T-Lam
ΓCa1:ABΓCa2:A
ΓCa1a2:B
T-App
ΓCa:AAcB
ΓCBApa:B
T-Cast
ΓCblamep:B
T-Blame

The value and evaluation-frame grammars are v::=bnλx:A.aA2B2A1B1pv?Gpv,F::=[]av[]BAp[]. Reduction is compatible with E::=[]F[E] and has exactly

(λx:A.a)va[v/x]
E-Beta
B{2,N}
BBpvv
E-IdBase
??pvv
E-IdUnk
G?p(?Gqv)v
E-Project
G1G2
G2?p(?G1qv)blamep
E-Mismatch
A?Agnd(A)
?Apv?gnd(A)p(gnd(A)Apv)
E-Ground
A?Agnd(A)
A?pvAgnd(A)p(gnd(A)?pv)
E-Expand
u=A2B2A1B1pv
uwB2B1p(v(A1A2p¯w))
E-WrapApp
F[blamep]blamep
E-Blame

The polar blame-safety orders are generated by

2+2
P-Bool
N+N
P-Nat
A+?
P-Unk
B1A1A2+B2
A1A2+B1B2
P-Arr
22
N-Bool
NN
N-Nat
?A
N-Unk
AG
A?
N-GroundUnk
B1+A1A2B2
A1A2B1B2
N-Arr

Here G is ground in N-GroundUnk.

Cast insertion has the complete table

Γbb:2
I-Bool
Γnn:N
I-Nat
x:AΓ
Γxx:A
I-Var
Γ,x:Aea:B
Γλx:A.eλx:A.a:AB
I-Lam
Γe1a1:Cfun(C)=ABΓe2a2:DDcA
Γ(e1e2)(ABCfa1)(ADaa2):B
I-App

Here f,a are globally fresh roots determined by .

Type and context precision are

Aty?
Pr-Unk
2ty2
Pr-Bool
NtyN
Pr-Nat
A1tyB1A2tyB2
A1A2tyB1B2
Pr-Arr
ctx
PrCtx-Empty
ΓctxΓAtyA
Γ,x:ActxΓ,x:A
PrCtx-Extend

Source-term precision is the least compatible relation generated by

bsrcb
PrTm-Bool
nsrcn
PrTm-Nat
xsrcx
PrTm-Var
AtyAesrce
λx:A.esrcλx:A.e
PrTm-Lam
e1srce1e2srce2
(e1e2)src(e1e2)
PrTm-App

For Δ=(x1:A1tyA1,,xn:AntyAn), target precision presupposes both projected target typings and the displayed result-type precision, where ΔL=(x1:A1,,xn:An),ΔR=(x1:A1,,xn:An). Its structural rules are

Δb:2Cb:2
CPr-Bool
Δn:NCn:N
CPr-Nat
x:AtyAΔ
Δx:ACx:A
CPr-Var
AtyAΔ,x:AtyAa:BCa:B
Δλx:A.a:ABCλx:A.a:AB
CPr-Lam
Δa1:ABCa1:ABΔa2:ACa2:A
Δa1a2:BCa1a2:B
CPr-App

The remaining rules are

Δa:SCa:SScTScTTtyT
ΔTSpa:TCTSpa:T
CPr-Cast
Δa:SCa:UScTTtyU
ΔTSpa:TCa:U
CPr-CastL
Δa:SCa:UUcVStyV
Δa:SCVUpa:V
CPr-CastR
ΔRCa:AAtyA
Δblamep:ACa:A
CPr-Blame

There is no rule relating an arbitrary left term to right-hand blame.

For Δ=(x1:A1tyA1,,xn:AntyAn), related closing substitutions are ρ=(v1/x1,,vn/xn)envρ=(v1/x1,,vn/xn) exactly when every vi,vi is closed and vi:AiCvi:Ai. Simultaneous substitution is written a[ρ].

Related evaluation frames have the rules

Δa:ACa:ABtyB
Δ[]a:(AB)BF[]a:(AB)B
FPr-AppL
Δv:ABCv:AB
Δv[]:ABFv[]:AB
FPr-AppR
StySScTScTTtyT
ΔTSp[]:STFTSp[]:ST
FPr-Cast

Evaluation-context precision is the reflexive transitive closure generated by

StyS
Δ[]:SSF[]:SS
FPr-Hole
ΔE:STFE:STΔF:TUFF:TU
ΔF[E]:SUFF[E]:SU
FPr-Cons

For a cast descriptor, the charge is χ(T,S):={3T=? and S is neither unknown nor ground,3S=? and T is neither unknown nor ground,1otherwise. The total cast weight cw(a) is structural: constants, variables, and blame contribute zero; abstraction takes its body’s weight; application adds both subterm weights; and cw(TSpa)=χ(T,S)+cw(a). With |a| the syntax-tree size, the stutter measure is st(a)=(cw(a),|a|)N×N in lexicographic order. Total weight includes descriptors in waiting arguments and beneath values, so a change of the next-redex position cannot increase the measure after an administrative cast contraction.

Separate dependent-interoperability card.

The SD comparison has a simply typed component s:S, a dependently typed component t:T, compatibility ST, and boundaries SDST(t):S,DSTS(s):T. For paired constructor declarations C:S1A and C:(y:T1)Bt1, the constructor-specific roots are SDABt(Cv)SDCuif argToSC(v)=u, and DSBtA(Cu)SD(t=~[v/y]t1)Cvif argToDC(u)=v. The guard returns its payload when the two closed first-order indices are equal and error otherwise. Call-by-value contexts descend into boundary operands. This card is the signature of definition 23.53; it adds no rule to the gradual cast calculus above.

Search the book

Type to search the local edition.