Lectures onType Theory
Modular type classes and implicit evidence
appendix sectionrules

Modular type classes and implicit evidence

The finite calculus uses constructor trees τ::=c(τ1,,τn), realized atomic signatures K[τ], and declarations F:K1[αj1],,Km[αjm]modK[c(α1,,αn)]. Every premise index satisfies jr{1,,n}. An environment is admissible exactly when all declarations have their displayed interfaces, every premise selects an immediate constructor argument, and no two declarations have the same result head (K,c). Its complete resolution rules are

P:K[c]Θ
ΘK[c]resP
R-Base
F:K1[αj1],,Km[αjm]modK[c(α1,,αn)]ΘΘKr[τjr]resVr(1rm)
ΘK[c(τ1,,τn)]resFV1,,Vm
R-Functor

Evidence typing is the least judgment generated by

P:K[c]Θ
ΘP:K[c]
T-EvPath
F:K1[αj1],,Km[αjm]modK[c(α1,,αn)]ΘΘVr:Kr[τjr](1rm)
ΘFV1,,Vm:K[c(τ1,,τn)]
T-EvFunctor

For the selected overloaded term fragment, ordinary forms elaborate homomorphically and the two evidence-inserting rules are

ΘEQ[τ]resVΓ;Θei:τei(i=1,2)
Γ;Θeq[τ](e1,e2):BoolV.eq e1 e2
E-Eq
ΘSHOW[τ]resVΓ;Θe:τe
Γ;Θshow[τ](e):StringV.show e
E-Show

The inserted evidence is typed in the target by

P:K[c]Θ
Γ;ΘP:K[c]
Mod-Path
Θ(F)=K¯[α¯]modK[c(α¯)]Γ;ΘVr:Kr[τjr](1rm)
Γ;ΘFV1,,Vm:K[c(τ¯)]
Mod-Functor
Γ;ΘV:K[τ]f:A(t) is a field of K
Γ;ΘV.f:A(τ)
Mod-Field

For modular implicits, let I;ΓScand{V1,,Vn} be the finite candidate set after solving the omitted module’s type-component equations. The call boundary is

I;ΓScand{V}Γf:{M:S}τ1τ2Γx:τ1
I;Γf xf{V}x:τ2
MI-Call

The SI fragment uses restricted types R::=XTT, full types T::=RT?TX.T, and one ordered context with explicit bindings x:T and implicit bindings y:T. Figure 3 is:

x:TΓ
ΓxTx
SI-Var
y:TΓ
Γ?Ty
SI-Query
Γ,x:SeTu
Γλx.eSTλx:S.u
SI-ArrI
Γe1STuΓe2Su
Γe1e2Tuu
SI-ArrE
y freshΓ,y:SeTu
ΓeS?Tλy:S.u
SI-ImpI
ΓeS?TuΓ?Su
ΓeTuu
SI-ImpE
Γ,XeTu
ΓeX.TΛX.u
SI-AllI
ΓeX.Tu
Γe[X:=S]Tu[S]
SI-AllE
Γe1TuΓ,x:Te2Ru
Γlet x:T=e1 in e2R(λx:T.u)u
SI-LetEx
Γe1Tuy freshΓ,y:Te2Ru
Γlet ?:T=e1 in e2R(λy:T.u)u
SI-LetIm
ΓeRu
ΓeRu
SI-Stitch

Here () maps both arrow forms to ordinary System F arrows. The rightmost choice is an external well-scopedness condition on derivations, not a premise of SI-Query.

Search the book

Type to search the local edition.