Lectures onType Theory
Functional objects and recursive object representations
appendix sectionrules

Functional objects and recursive object representations

For distinct labels, the source extension is A::=[i:Bi]iI,a::=[i=ς(si:A)bi]iI::=a.a.ς(s:A)b. Its three primitive typing rules are

A=[i:Bi]iIΓ,si:Abi:Bi (iI)
Γ[i=ς(si:A)bi]iI:A
T-Object
Γa:[i:Bi]iIjI
Γa.j:Bj
T-Invoke
Γa:AA=[i:Bi]iIΓ,s:Ab:BjjI
Γa.jς(s:A)b:A
T-Override

Objects are values, evaluation is weak. Put v=[i=ς(si:A)bi]iI. The roots are v.jbj[v/sj],v.jς(s:A)c[j=ς(s:A)c,i=ς(si:A)bi]ij. The second root records the runtime minimum type A, where A<:A. Width-invariant subtyping and subsumption are

A<:Top
S-Top
JIBj=Cj (jJ)
[i:Bi]iI<:[j:Cj]jJ
S-Object
Γa:AA<:B
Γa:B
T-Sub

Minimum typing removes T-Sub; variables, ground forms, and invocation remain syntax directed, while formation and override become

A=[i:Bi]iIΓ,si:Aminbi:BiBi<:Bi (iI)
Γmin[i=ς(si:A)bi]iI:A
M-Object
A=[i:Bi]iIΓmina:AA<:AΓ,s:Aminb:BB<:BjjI
Γmina.jς(s:A)b:A
M-Override
Γmina:[i:Bi]iIjI
Γmina.j:Bj
M-Invoke

Fluent methods use the iso-recursive equation Point=μX.[x:Nat,get:Nat,move:X] with the fold/unfold rules of subappendix A.21.

The translation target F<:μ adds arrows, covariant records, bounded existentials, and iso-recursive types. Its characteristic subtyping calculus has formation rules

ΔS typeΔT type
ΔST type
FT-Arr
ΔSi type(iI)
Δ{ki:Si}iI type
FT-Record
ΔS typeΔ,X<:ST type
ΔX<:S.T type
FT-Exists
Δ,X<:TopT type
ΔμX.T type
FT-Mu

Its structural subtyping rules are

ΔS type
ΔS<:S
S-Refl
ΔR<:SΔS<:T
ΔR<:T
S-Trans
X<:SΔ
ΔX<:S
S-Bound
ΔS type
ΔS<:Top
S-Top

Its characteristic subtyping rules are

S<:ST<:T
ST<:ST
S-Arr
JISj<:Tj (jJ)
{ki:Si}iI<:{kj:Tj}jJ
S-Rec
S<:SX<:ST<:T
X<:S.T<:X<:S.T
S-Exists
Y<:Top,X<:YS<:T
μX.S<:μY.T
S-Amber

Ordinary target typing is generated by

x:SΓ
Δ;Γx:S
F-Var
Δ;Γt:SΔS<:T
Δ;Γt:T
F-Sub
Δ;Γ,x:St:T
Δ;Γλx:S.t:ST
F-Lam
Δ;Γt:STΔ;Γu:S
Δ;Γtu:T
F-App
Δ;Γti:Si(iI)
Δ;Γ{ki=ti}iI:{ki:Si}iI
F-Record
Δ;Γt:{ki:Si}iIjI
Δ;Γt.kj:Sj
F-Proj

The exact boundary rules are

R<:SΔ;Γt:T[R/X]
Δ;Γpack X<:S=R with t as X<:S.T:X<:S.T
F-Pack
Δ;Γp:X<:S.TΔ,X<:S;Γ,x:Tu:UXFV(U)
Δ;Γ(open p as X<:S,x:T in u):U
F-Open
Δ;Γt:T[μX.T/X]
Δ;ΓfoldμX.Tt:μX.T
F-Fold
Δ;Γt:μX.T
Δ;Γunfoldt:T[μX.T/X]
F-Unfold

If F=S1SnT, recursive creation is typed by

Δ;Γ,f:F,x1:S1,,xn:Snt:TΔ;Γ,f:Fu:U
Δ;Γletrec f(xi:Si)i=1n:T=t in u:U
F-Letrec

Opening an actual package annotated Y<:S0.T0 at a subsumed existential type contracts using its actual witness and payload: open(pack Y<:S0=R with t as Y<:S0.T0)as X<:S,x:T in uu[R/X][t/x]. For A=[i:Bi]iI, put A=μY.X<:Y.CA(X),CA(X)={isel:XBi,self:X,iupd:(XBi)X}iI. The recursive declaration is DAcreate(fi:ABi)iI:A=foldA(pack X<:A=A with{isel=fi,iupd=λg:ABi.create(f¯[i:=g]),self=create(f¯)}as X<:A.CA(X)). With rDA=letrec DA in create, the exact object clause is trΓ([i=ς(si:A)bi]iI)=rDA(λsi:A.trΓ,si:A(bi))iI. Unfolding the recursive function places the literal same term rDA(f¯) in its self field and places rDA(f¯[i:=g]) in update field i. Invocation unfolds, opens, selects jsel, and supplies self; override selects jupd and supplies the translated replacement.

Search the book

Type to search the local edition.