Monadic form [UP3Y]

如果讓let表示monadic bind,讓return隱含在values下,那monadic form有以下commuting conversions

let (x U) E[x]=E[U](Left Identity)let (x C) x=C(Right Identity)let (y (let (x C) C1)) C2=let (x C) (let (y C1) C2)(Associativity)let (x (if0 U C1 C2)) C=if0 U (let (x C1) C) (let (x C2) C)(Commute)\begin{aligned} \text{let}\ (x\ U)\ E[x] &= E[U] \quad&\text{(Left Identity)} \\ \text{let}\ (x\ C)\ x &= C \quad&\text{(Right Identity)} \\ \text{let}\ (y\ (\text{let}\ (x\ C)\ C_1))\ C_2 &= \text{let}\ (x\ C)\ (\text{let}\ (y\ C_1)\ C_2) \quad&\text{(Associativity)} \\ \text{let}\ (x\ (\text{if0}\ U\ C_1\ C_2))\ C &= \text{if0}\ U\ (\text{let}\ (x\ C_1)\ C)\ (\text{let}\ (x\ C_2)\ C) \quad&\text{(Commute)} \end{aligned}

ANF可以定義成monadic form用associativity跟commute這兩條規則normalize的結果