Lectures onType Theory
Higher-order signatures and modular elaboration
appendix sectionrules

Higher-order signatures and modular elaboration

An ordinary signature Δ consists of operations OpΔ and response sets RetΔ(o). Its disjoint sum is OpΔ1sigΔ2=OpΔ1+OpΔ2,RetΔ1sigΔ2(ιio)=RetΔi(o). A higher-order signature H consists of OpHH,ForkH(o),RetHH(o). Here ForkH(o) is itself an ordinary signature and describes the nested computations owned by o. The sum H1H2 is the disjoint sum of operation tags, with fork and return families selected by cases on the tag.

For A:Set, hefty trees have constructors pure(a):HeftyH(A),impure(o,ψ,k):HeftyH(A), where ψ:s:OpForkH(o)HeftyH(RetForkH(o)(s)),k:RetHH(o)HeftyH(A). The source bind traverses only the ordinary continuation: pure(x)=Hg=g(x),impure(o,ψ,k)=Hg=impure(o,ψ,λx.k(x)=Hg). Traversing ψ would push the continuation into operation-owned subcomputations and is generally ill typed.

For a family G:SetSet, a hefty algebra has components αA(o,,):(s:OpForkH(o)G(RetForkH(o)(s)))(RetHH(o)G(A))G(A). Given gX:XG(X) at every X, its catamorphism is catag,αH(pure(x))=g(x),catag,αH(impure(o,ψ,k))=α(o,catag,αHψ,catag,αHk). For G(X)=FreeΔ(X) and g=pure, an algebra E is an elaboration and the catamorphism is elaborateE. Component composition is operation-tag dispatch: (E1E2)(inlo,ψ,k)=E1(o,ψ,k),(E1E2)(inro,ψ,k)=E2(o,ψ,k).

The higher-order catch operation at code t has ForkCatch(catch(t))=(2,λb.Val(t)),RetCatchH(catch(t))=Val(t). For a throw insertion witness w, write h=runThroww. Its equations and the residual-operation reinjection are h(pure(x))=pure(just(x)),h(throw)=pure(nothing),h(res(o,k))=impure(o,λr.h(k(r))),maskw(pure(x))=pure(x),maskw(impure(o,k))=res(o,λr.maskw(k(r))). The catch component is Ecatch(catch(t),ψ^,k^)=maskw(h(ψ^(tt)))=maybe(k^,ψ^(ff)=k^). The state component used by the chapter discards the final state: runStates(pure(x))=pure(x),runStates(put(n,k))=runStaten(k()),runStates(get(k))=runStates(k(s)),runStates(res(o,k))=impure(o,λr.runStates(k(r))).

Search the book

Type to search the local edition.