Definition. Non-strict monadic evaluation contexts與B-normalization [PIBK]

Non-strict monadic evaluation contexts EbE^b

Eb::=⋅∣(if0 Eb e e)∣(Eb e)∣(v Eb)∣(op v⃗ Eb e⃗)E^b ::= \cdot \mid (\text{if0}\ E^b\ e\ e) \mid (E^b\ e) \mid (v\ E^b) \mid (op\ \vec{v}\ E^b\ \vec{e})

B-reductions

Eb[(let (x e1) e2)]→let (x e1) Eb[e2]B1where Eb≠⋅Eb[(if0 v e1 e2)]→let (y (if0 v e1 e2))Eb[y]B2where Eb≠⋅,fresh yEb[(O v⃗)]→let (y (O v⃗)) Eb[y]B3where Eb≠⋅,fresh y\begin{aligned} E^b[(\text{let}\ (x\ e_1)\ e_2)] \quad\rightarrow\quad &\text{let}\ (x\ e_1)\ E^b[e_2]\quad &B_1 \\ &\text{where}\ E^b \ne \cdot \\ E^b[(\text{if0}\ v\ e_1\ e_2)] \quad\rightarrow\quad &\text{let}\ (y\ (\text{if0}\ v\ e_1\ e_2)) E^b[y]\quad &B_2 \\ &\text{where}\ E^b \ne \cdot, \text{fresh}\ y \\ E^b[(O\ \vec{v})] \quad\rightarrow\quad &\text{let}\ (y\ (O\ \vec{v}))\ E^b[y]\quad &B_3 \\ &\text{where}\ E^b \ne \cdot, \text{fresh}\ y \end{aligned}

如果定義 B={B1,B2,B3}B = \{B_1, B_2, B_3\},那麼這組規則會確保evaluation position上的non-value會被換成value。

Example 避免程式指數爆炸成長 [local-0]

相比起 A2A_2 規則,B2B_2 專門用來避免程式指數爆炸的轉換。我們再次回到失敗案例然後推導變換過程

let x := if0 (if0 (if0 0 0 1) 0 1) 0 1
in LARGE

我們改用 Eb[−]E^b[-] 來轉換,由於不抽取let-if,所以我們要直接處理rhs,於是

let x :=
  let y := if0 (if0 0 0 1) 0 1
  in if0 y 0 1
in LARGE

下一步

let x :=
  let z := if0 0 0 1
  in let y := if0 z 0 1
  in if0 y 0 1
in LARGE

所以這確實不會導致大量的程式碼重複