For a finite signature Σ(𝗈𝗉)=𝑃𝗈𝗉⇝𝑅𝗈𝗉, well-founded operation trees, return, bind, and the handler fold are 𝑡::=𝖱𝖾𝗍(𝑎)∣𝖮𝗉𝗈𝗉(𝑝,𝑘),𝑘:𝑅𝗈𝗉→𝑇Σ𝐴,𝗋𝖾𝗍𝗎𝗋𝗇𝑎=𝖱𝖾𝗍(𝑎),𝖱𝖾𝗍(𝑎)≫=𝑓=𝑓(𝑎),𝖮𝗉𝗈𝗉(𝑝,𝑘)≫=𝑓=𝖮𝗉𝗈𝗉(𝑝,𝜆𝑟.𝑘(𝑟)≫=𝑓),𝖿𝗈𝗅𝖽𝑟,ℎ(𝖱𝖾𝗍(𝑎))=𝑟(𝑎),𝖿𝗈𝗅𝖽𝑟,ℎ(𝖮𝗉𝗈𝗉(𝑝,𝑘))=ℎ𝗈𝗉(𝑝,𝜆𝑞.𝖿𝗈𝗅𝖽𝑟,ℎ(𝑘(𝑞))). Here ℎ𝗈𝗉:𝑃𝗈𝗉→(𝑅𝗈𝗉→𝐶)→𝐶. A fold descends through a quotient by an effect theory exactly when it equalizes every generating equation under every tree-valued instantiation. It is sufficient, but stronger, for the entire Σ-algebra to satisfy every generating equation under every carrier-valued assignment.
The source calculus used by the call-by-value and call-by-name translations has the complete typing rules
𝑥:𝜏∈Γ
Γ⊢𝑥:𝜏
S-Var
𝑐:𝑏isdeclared
Γ⊢𝑐:𝑏
S-Const
Γ,𝑥:𝜏⊢𝑒:𝜎
Γ⊢𝜆𝑥.𝑒:𝜏→𝜎
S-Lam
Γ⊢𝑒1:𝜏→𝜎Γ⊢𝑒2:𝜏
Γ⊢𝑒1𝑒2:𝜎
S-App
Writing (w) for a source constant or lambda, the two big-step relations are
𝑤⇓𝑣𝑤
V-Val
𝑒1⇓𝑣𝜆𝑥.𝑒𝑒2⇓𝑣𝑤2𝑒[𝑤2/𝑥]⇓𝑣𝑤
𝑒1𝑒2⇓𝑣𝑤
V-App
𝑤⇓𝑛𝑤
N-Val
𝑒1⇓𝑛𝜆𝑥.𝑒𝑒[𝑒2/𝑥]⇓𝑛𝑤
𝑒1𝑒2⇓𝑛𝑤
N-App
The effect-free calculus 𝖢𝖡𝖯𝖵0 has 𝐴::=𝑏∣𝑈𝐶,𝐶::=𝐹𝐴∣𝐴⇒𝐶,𝑉::=𝑥∣𝑐∣𝗍𝗁𝗎𝗇𝗄𝑀,𝑀::=𝗋𝖾𝗍𝗎𝗋𝗇𝑉∣𝑀𝗍𝗈𝑥.𝑁∣𝖿𝗈𝗋𝖼𝖾𝑉::=∣𝜆𝑥.𝑀∣𝑀𝑉. Its complete typing rules are
𝑥:𝐴∈Γ
Γ⊢𝑣𝑥:𝐴
V-Var
𝑐:𝑏declared
Γ⊢𝑣𝑐:𝑏
V-Const
Γ⊢𝑐𝑀:𝐶
Γ⊢𝑣𝗍𝗁𝗎𝗇𝗄𝑀:𝑈𝐶
V-Thunk
Γ⊢𝑣𝑉:𝐴
Γ⊢𝑐𝗋𝖾𝗍𝗎𝗋𝗇𝑉:𝐹𝐴
C-Return
Γ⊢𝑐𝑀:𝐹𝐴Γ,𝑥:𝐴⊢𝑐𝑁:𝐶
Γ⊢𝑐𝑀𝗍𝗈𝑥.𝑁:𝐶
C-To
Γ⊢𝑣𝑉:𝑈𝐶
Γ⊢𝑐𝖿𝗈𝗋𝖼𝖾𝑉:𝐶
C-Force
Γ,𝑥:𝐴⊢𝑐𝑀:𝐶
Γ⊢𝑐𝜆𝑥.𝑀:𝐴⇒𝐶
C-Lam
Γ⊢𝑐𝑀:𝐴⇒𝐶Γ⊢𝑣𝑉:𝐴
Γ⊢𝑐𝑀𝑉:𝐶
C-App
Weak evaluation uses 𝐾::=[]∣𝐾𝗍𝗈𝑥.𝑁∣𝐾𝑉 and the named roots (𝗋𝖾𝗍𝗎𝗋𝗇𝑉)𝗍𝗈𝑥.𝑁⟶𝑁[𝑉/𝑥],𝑇𝑜𝖿𝗈𝗋𝖼𝖾(𝗍𝗁𝗎𝗇𝗄𝑀)⟶𝑀,𝐹𝑜𝑟𝑐𝑒(𝜆𝑥.𝑀)𝑉⟶𝑀[𝑉/𝑥],𝐵𝑒𝑡𝑎𝐾[𝑀]⟶𝐾[𝑀′](𝑀⟶𝑀′).𝐹𝑟𝑎𝑚𝑒
For the annotated extension, 𝐴::=𝑏∣𝑈E𝐶,𝐶::=𝐹𝐴∣𝐴⇒E𝐶,Γ⊢𝑐𝑀:𝐶!E. The variable and constant rules remain unchanged. The complete replacement rules are
Γ⊢𝑐𝑀:𝐶!E
Γ⊢𝑣𝗍𝗁𝗎𝗇𝗄𝑀:𝑈E𝐶
V-Thunk^Σ
Γ⊢𝑣𝑉:𝐴
Γ⊢𝑐𝗋𝖾𝗍𝗎𝗋𝗇𝑉:𝐹𝐴!∅
C-Return^Σ
Γ⊢𝑐𝑀:𝐹𝐴!E1Γ,𝑥:𝐴⊢𝑐𝑁:𝐶!E2
Γ⊢𝑐𝑀𝗍𝗈𝑥.𝑁:𝐶!(E1∪E2)
C-To^Σ
Γ⊢𝑣𝑉:𝑈E𝐶
Γ⊢𝑐𝖿𝗈𝗋𝖼𝖾𝑉:𝐶!E
C-Force^Σ
Γ,𝑥:𝐴⊢𝑐𝑀:𝐶!E
Γ⊢𝑐𝜆𝑥.𝑀:𝐴⇒E𝐶!∅
C-Lam^Σ
Γ⊢𝑐𝑀:𝐴⇒E1𝐶!E0Γ⊢𝑣𝑉:𝐴
Γ⊢𝑐𝑀𝑉:𝐶!(E0∪E1)
C-App^Σ
Σ(𝗈𝗉)=𝑃⇝𝑅Γ⊢𝑣𝑉:𝑃Γ,𝑥:𝑅⊢𝑐𝑀:𝐹𝐴!E
Γ⊢𝑐𝗈𝗉𝑉(𝑥.𝑀):𝐹𝐴!({𝗈𝗉}∪E)
C-Op
Γ⊢𝑐𝑀:𝐶!EE⊆E′
Γ⊢𝑐𝑀:𝐶!E′
C-Weaken
The fixed pure state update used by the worked transaction is typed by
Γ⊢𝑣𝑉:𝑆
Γ⊢𝑣𝑉+:𝑆
V-Next
A handler is 𝐻={𝗋𝖾𝗍𝗎𝗋𝗇𝑥↦𝑁𝑟;𝗈𝗉𝑖(𝑝𝑖;𝑘𝑖)↦𝑁𝑖}𝑖∈𝐼, with distinct operation names and H=𝗁𝖺𝗇𝖽𝗅𝖾𝖽(𝐻). The judgment Γ⊢ℎ𝐻:𝐴[Ein]⟹𝐵[Eout] means all of the following premises hold: Ein∖H⊆Eout,Γ,𝑥:𝐴⊢𝑐𝑁𝑟:𝐹𝐵!Eout,Γ,𝑝𝑖:𝑃𝑖,𝑘𝑖:𝑈∅(𝑅𝑖⇒Eout𝐹𝐵)⊢𝑐𝑁𝑖:𝐹𝐵!Eout for every handled 𝗈𝗉𝑖 with Σ(𝗈𝗉𝑖)=𝑃𝑖⇝𝑅𝑖. Its elimination rule is
Γ⊢𝑐𝑀:𝐹𝐴!EinΓ⊢ℎ𝐻:𝐴[Ein]⟹𝐵[Eout]
Γ⊢𝑐𝗁𝖺𝗇𝖽𝗅𝖾𝑀𝗐𝗂𝗍𝗁𝐻:𝐹𝐵!Eout
C-Handle
For an 𝗈𝗉-open evaluation context 𝑋𝗈𝗉, let ̂𝑘=𝗍𝗁𝗎𝗇𝗄(𝜆𝑦.𝗁𝖺𝗇𝖽𝗅𝖾𝑋𝗈𝗉[𝑀[𝑦/𝑥]]𝗐𝗂𝗍𝗁𝐻). The exact deep-handler roots are 𝗁𝖺𝗇𝖽𝗅𝖾(𝗋𝖾𝗍𝗎𝗋𝗇𝑉)𝗐𝗂𝗍𝗁𝐻⟶𝑁𝑟[𝑉/𝑥],𝐻𝑎𝑛𝑑𝑙𝑒−𝑅𝑒𝑡𝑢𝑟𝑛,𝗁𝖺𝗇𝖽𝗅𝖾𝑋𝗈𝗉[𝗈𝗉𝑉(𝑥.𝑀)]𝗐𝗂𝗍𝗁𝐻⟶𝑁𝗈𝗉[𝑉/𝑝,̂𝑘/𝑘],𝐻𝑎𝑛𝑑𝑙𝑒−𝑂𝑝 when 𝐻 contains the displayed operation clause. If it does not, the Handle-Forward rule is 𝗁𝖺𝗇𝖽𝗅𝖾𝑋𝗈𝗉[𝗈𝗉𝑉(𝑥.𝑀)]𝗐𝗂𝗍𝗁𝐻⟶𝗈𝗉𝑉(𝑦.𝗁𝖺𝗇𝖽𝗅𝖾𝑋𝗈𝗉[𝑀[𝑦/𝑥]]𝗐𝗂𝗍𝗁𝐻). In the first-order agreement fragment, 𝑋::=[]∣𝑋𝗍𝗈𝑥.𝐿∣𝗁𝖺𝗇𝖽𝗅𝖾𝑋𝗐𝗂𝗍𝗁𝐺,𝗈𝗉∉𝗁𝖺𝗇𝖽𝗅𝖾𝖽(𝐺), and general application is excluded; only administrative resumed continuations are admitted.