Introduction Body Summary
Encapsulation of State with Monad Transformers Steven E. Ganz
Indiana University Computer Science Department Doctoral Defense 12/08/2006 iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Research Committee
Chair: Daniel P. Friedman Christopher T. Haynes
David Charles McCarty
Paul W. Purdom, Jr.
Computer Science Department
Philosophy Department
Computer Science Department
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Outline
1
Introduction
2
Body State Dynamics Statics Translation Enhancements
3
Summary iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Regions and Encapsulation Regions “layer” effects, associating them with statically determinable portions of programs Encapsulation guarantees effects are constrained by regions
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Regions and Encapsulation Regions “layer” effects, associating them with statically determinable portions of programs Encapsulation guarantees effects are constrained by regions Why Effects make programs harder to manipulate. Encapsulation allows for more transformations. How letregion construct names a region and opens a scope. Static rules conservatively estimate the effects.
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Regions and Encapsulation Regions “layer” effects, associating them with statically determinable portions of programs Encapsulation guarantees effects are constrained by regions Why Effects make programs harder to manipulate. Encapsulation allows for more transformations. How letregion construct names a region and opens a scope. Static rules conservatively estimate the effects. Regions Under Various Effects state area of memory multithreading process queue exceptions vector of handlers continuations level of “meta-continuations” Steven E. Ganz
Encapsulation of State with Monad Transformers
iu-logo
Introduction Body Summary
A Requirement
Regions must be “permeable”, i.e., encapsulation allows for dependencies, safe escapes.
Example letregion ρ1 in let outerRef1 = @ ρ1 href truei i in let outerRef2 = @ ρ1 href letregion ρ2 in let innerRef = @ ρ2 href deref outerRef1 i in set outerRef1 to deref innerRef; innerRef in deref outerRef2 iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
A Requirement Regions must be “permeable”, i.e., encapsulation allows for dependencies, safe escapes. Example
true
ρ
1
oR1: [ oR2 : ]
ρ
2
>
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Monad Transformers Monads represent computations with effects. return makes a trivial computation. let makes the result of one computation accessible to another computation. run runs a computation, taking one out of the monad. Monad transformers allow for modular representations. return adds a trivial layer of computation. let makes the result of one computation accessible to another computation. run removes a layer of computation. iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Monad Transformer per Region Approach My Thesis: Monad transformers provide a modular representation of programs with encapsulated effects.
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Monad Transformer per Region Approach My Thesis: Monad transformers provide a modular representation of programs with encapsulated effects. Use run to introduce a region Use return to either Introduce simple values Define dependent computations at outer regions
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Monad Transformer per Region Approach My Thesis: Monad transformers provide a modular representation of programs with encapsulated effects. Use run to introduce a region Use return to either Introduce simple values Define dependent computations at outer regions
ρ
1
ρ
2
A limitation:
No upward/inward references.
We disallow: letregion ρ1 in letregion ρ2 in @ ρ1 href @ ρ2 href unitii
unit
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Monad Transformer per Region Approach My Thesis: Monad transformers provide a modular representation of programs with encapsulated effects. Use run to introduce a region Use return to either Introduce simple values Define dependent computations at outer regions
A limitation:
No upward/inward references.
A benefit: Regions need not be mentioned explicitly. They don’t need to be part of addresses, process ids, etc. A further benefit: The same holds for the type system. iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Effects Expression
e
Trace
hr, oi
t
[]
Effect
ε
∅
(b = hλx.e i, href ei, etc.) [(alloc @ hr, oi)]
{(alloc @ ̺)}
deref e
[(read @ hr, oi)]
{(read @ ̺)}
set e1 to e2
[(write @ hr1 , o1 i)] {(write @ ̺1 )}
e1 e2
[(exec @ hr1 , o1 i)] {(exec @ ̺1 )}
let x = e1 in e2
t1 + t2
@̺ b
Steven E. Ganz
ε1 ∪ ε2
Encapsulation of State with Monad Transformers
iu-logo
Introduction Body Summary
State Dynamics Statics Translation Enhancements
The State Monad Assume a store type S. hεSt , ⊥St , _ ⊔St _i
= h {alloc,read,write,exec} , ∅, _ ∪ _i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
The State Monad Assume a store type S. hεSt , ⊥St , _ ⊔St _i
= h {alloc,read,write,exec} , ∅, _ ∪ _i
Stε P
= (P × S)S
Stε f
= λmv.λs.let hv, si = mv s in hf v, si
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
The State Monad Assume a store type S. hεSt , ⊥St , _ ⊔St _i
= h {alloc,read,write,exec} , ∅, _ ∪ _i
Stε P
= (P × S)S
Stε f
= λmv.λs.let hv, si = mv s in hf v, si
ηSt P
= λv.λs.hv, si
µPSt,_,_
= λmmv.λs.let hmv, si = mmv s in mv s
f
∗PSt ,_,_ ,P 1
2
= λmv.λs.let hv, si = mv s in f v s iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
The State Monad Assume a store type S. hεSt , ⊥St , _ ⊔St _i
= h {alloc,read,write,exec} , ∅, _ ∪ _i
Stε P
= (P × S)S
Stε f
= λmv.λs.let hv, si = mv s in hf v, si
ηSt P
= λv.λs.hv, si
µPSt,_,_
= λmmv.λs.let hmv, si = mmv s in mv s
f
∗PSt ,_,_ ,P 1
ζSt ε
2
= λmv.λs.let hv, si = mv s in f v s = λmv.let hv, si = mv sinit in v Steven E. Ganz
Encapsulation of State with Monad Transformers
iu-logo
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Monad Operators ref
:C
P → St{alloc} Ref P λv.λs.ho, s {o → 7 v}i
=
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Monad Operators ref
:C
deref :C
P → St{alloc} Ref P λv.λs.ho, s {o → 7 v}i
=
Ref P → St{read} P λo.λs.hs o, si
=
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Monad Operators ref
:C
deref :C
set
:C
P → St{alloc} Ref P λv.λs.ho, s {o → 7 v}i
=
Ref P → St{read} P λo.λs.hs o, si
=
Ref P × P → St{write} Unit λho, vi.λs.hunit, s {o v}i
=
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Monad Operators ref
:C
deref :C
P → St{alloc} Ref P λv.λs.ho, s {o → 7 v}i
=
Ref P → St{read} P λo.λs.hs o, si
=
=
set
:C
Ref P × P → St{write} Unit λho, vi.λs.hunit, s {o v}i
abs
:C
(Stε P2 )P1 → St{alloc} (P1 ⇒ (Stε P2 )) = λf .λs.ho, s {o 7→ f }i iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Monad Operators ref
:C
deref :C
P → St{alloc} Ref P λv.λs.ho, s {o → 7 v}i
=
Ref P → St{read} P λo.λs.hs o, si
=
=
set
:C
Ref P × P → St{write} Unit λho, vi.λs.hunit, s {o v}i
abs
:C
(Stε P2 )P1 → St{alloc} (P1 ⇒ (Stε P2 )) = λf .λs.ho, s {o 7→ f }i
app
:C (P1 ⇒ Stε P2 ) × P1 → St{exec} ∪ ε P2 λho, vi.λs.s o v s Steven E. Ganz
Encapsulation of State with Monad Transformers
=
iu-logo
Introduction Body Summary
State Dynamics Statics Translation Enhancements
The State Monad Transformer Assume a region store type ≬S. hεSt , ⊥St , _ ⊔St _i
= h {alloc,read,write,exec} , ∅, _ ∪ _i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
The State Monad Transformer Assume a region store type ≬S. hεSt , ⊥St , _ ⊔St _i ε
M ε M
St P M ε ε St M f
= h {alloc,read,write,exec} , ∅, _ ∪ _i M ε (M
≬ ≬S)) S
= (P × M ≬ ε = λtmv.λ s.M (λhv, ≬si.hf v, ≬si) (tmv ≬s)
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
The State Monad Transformer Assume a region store type ≬S. hεSt , ⊥St , _ ⊔St _i ε
M ε M
St P M ε ε St M f St,M,εM
ηP
St M M St M,hεSt 1 , ε1 i,hε2 , ε2 i µP
f
, εM i,hεT St M,hεSt , εM 1 2 2 i 1 ∗P ,P 1 2
= h {alloc,read,write,exec} , ∅, _ ∪ _i M ε (M
≬ ≬S)) S
= (P × M ≬ ε = λtmv.λ s.M (λhv, ≬si.hf v, ≬si) (tmv ≬s) M,εM ,⊥M ∗ P,P × ≬S
≬si) = λma.λ≬s.(λv.ηM hv, ≬ P× S
ma
,εM M,εM 2 1 ∗ St M P × ≬S ,P × ≬S
= λtmtmv.λ≬s.(λhtmv, ≬si.tmv ≬s) (tmtmv ≬s) = λtmv.λ≬s.(λhv, ≬si.f v ≬s)
M,εM ,εM 1 2 ∗ ≬ p1 × S ,P2 × ≬S
(tmv ≬s) iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
The State Monad Transformer Assume a region store type ≬S. hεSt , ⊥St , _ ⊔St _i ε
M ε M
St P M ε ε St M f St,M,εM
ηP
St M M St M,hεSt 1 , ε1 i,hε2 , ε2 i µP
f
, εM i,hεT St M,hεSt , εM 1 2 2 i 1 ∗P ,P 1 2
ζSt,M,ε
St ,εM
= h {alloc,read,write,exec} , ∅, _ ∪ _i M ε (M
≬ ≬S)) S
= (P × M ≬ ε = λtmv.λ s.M (λhv, ≬si.hf v, ≬si) (tmv ≬s) M,εM ,⊥M ∗ P,P × ≬S
≬si) = λma.λ≬s.(λv.ηM hv, ≬ P× S
ma
,εM M,εM 2 1 ∗ St M P × ≬S ,P × ≬S
= λtmtmv.λ≬s.(λhtmv, ≬si.tmv ≬s) (tmtmv ≬s) = λtmv.λ≬s.(λhv, ≬si.f v ≬s) = λtmv.(λhv, ≬si.ηM P v) Steven E. Ganz
M,εM ,εM 1 2 ∗ ≬ p1 × S ,P2 × ≬S
M,εM ,⊥M ∗ P × ≬S ,P
(tmv ≬s)
(tmv ≬s init )
Encapsulation of State with Monad Transformers
iu-logo
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Monad Transformer Operators refM
:Ci+1
P
→ St{alloc} M ⊥ (Ref P)
=
λv.λ≬s .ηSt M ho, ≬s {o 7→ v}i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Monad Transformer Operators refM
:Ci+1
P
→ St{alloc} M ⊥ (Ref P)
=
λv.λ≬s .ηSt M ho, ≬s {o 7→ v}i derefM :Ci+1
Ref P → St{read} M ⊥ P λo.λ≬s.ηSt M h≬s o, ≬si
=
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Monad Transformer Operators refM
:Ci+1
P
→ St{alloc} M ⊥ (Ref P)
=
λv.λ≬s .ηSt M ho, ≬s {o 7→ v}i derefM :Ci+1
Ref P → St{read} M ⊥ P λo.λ≬s.ηSt M h≬s o, ≬si
=
setM
((Ref P) × P) → St{write} M ⊥ (Returni Unit) λho, vi.λ≬s.ηSt M hunit, ≬s {o v}i
=
:Ci+1
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Monad Transformer Operators refM
:Ci+1
P
→ St{alloc} M ⊥ (Ref P)
=
λv.λ≬s .ηSt M ho, ≬s {o 7→ v}i derefM :Ci+1
Ref P → St{read} M ⊥ P λo.λ≬s.ηSt M h≬s o, ≬si
=
setM
:Ci+1
((Ref P) × P) → St{write} M ⊥ (Returni Unit) λho, vi.λ≬s.ηSt M hunit, ≬s {o v}i
=
absM
:Ci+1
(Stε1 M ε2 P2 ) 1 → St{alloc} M ⊥ (P1 ⇒ Stε1 M ε2 P2 ) λf .λ≬s .ηSt M ho, ≬s {o 7→ f }i
P
=
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
State Monad Transformer Operators refM
:Ci+1
P
→ St{alloc} M ⊥ (Ref P)
=
λv.λ≬s .ηSt M ho, ≬s {o 7→ v}i derefM :Ci+1
Ref P → St{read} M ⊥ P λo.λ≬s.ηSt M h≬s o, ≬si
=
setM
:Ci+1
((Ref P) × P) → St{write} M ⊥ (Returni Unit) λho, vi.λ≬s.ηSt M hunit, ≬s {o v}i
=
absM
:Ci+1
(Stε1 M ε2 P2 ) 1 → St{alloc} M ⊥ (P1 ⇒ Stε1 M ε2 P2 ) λf .λ≬s .ηSt M ho, ≬s {o 7→ f }i
appM :Ci+1
P
(P1 ⇒ Stε1 M ε2 P2 ) × P1 → (St{exec} ∪ ε1 M ε2 ) P2 λho, vi.λ≬s.≬s o v ≬s Steven E. Ganz
Encapsulation of State with Monad Transformers
=
= iu-logo
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Addresses Under Various Models of State
Unencapsulated Encapsulated Direct
address := offset address := region & offset
Monadic address := offset address := offset
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
The Return Functor Given two linked cells in two regions, type from inner region as: Ref Ref Return Return Unit [ ]
if both cells in inner region unit
Ref Return Ref Return Unit
if one cell in each region
[ ]
unit
Return Ref Ref Return Unit
if both cells in outer region
[ ][ Steven E. Ganz]
iu-logo
unit Encapsulation of State with Monad Transformers
State Dynamics Statics Translation Enhancements
Introduction Body Summary
Incremental Development of Implementation Category Functor: Nat trans:
C2 C1
C0
Id
St Id
return
return
Return Return P
Return P
P0
2
St Id
1
2
Ref
... Ref
Unit
φ φ φ iu-logo
1 Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Some Object Language Reduction Rules
⇀ he ; s ir
⇀ he ; s ir
-letregion [] hletregion ρ0 in e0 ; s1 i ⇀ hfreeregion r0 after e0 [ ρ0 := r0 ] ; s1 {r0 7→ ∅}i -freeregion hfreeregion r0 after v0 ; s1 {r0 7→
≬s
0 }i
[]
⇀ hv0 [ r0 := ∅] ; s1 i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
An Object Language Evaluation Context
→∗ [ e]
(
→∗ [ t] r ^ r0
→∗ [ e]
→∗ [ t]
r ^ r0
e! t) ∈ ( e! t) (freeregion r0 after [ e] ! [ t] − r0 )
::=
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h letregion ρ1 in let x2 = @ ρ1 href uniti in letregion ρ2 in let x3 = @ ρ2 href x2 i in @ ρ1 @ ρ1 hλx1 .@ ρ1 deref letregion ρ3 in x2 i @ ρ2 deref x3 ∅i [ ]
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after let x2 = @ r1 href uniti in letregion ρ2 in let x3 = @ ρ2 href x2 i in @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in x2 i @ ρ2 deref x3 ∅ {r1 7→ ∅}i [ ] − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after let x2 = @ r1 href uniti in letregion ρ2 in let x3 = @ ρ2 href x2 i in @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in x2 i @ ρ2 deref x3 ∅ {r1 7→ ∅}i [ ] − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after let x2 = hr1 , o1 i in letregion ρ2 in let x3 = @ ρ2 href x2 i in @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in x2 i @ ρ2 deref x3 ∅ {r1 7→ ∅ {o1 7→ href uniti}}i [ (alloc @ hr1 , o1 i) ] − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after let x2 = hr1 , o1 i in letregion ρ2 in let x3 = @ ρ2 href x2 i in @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in x2 i @ ρ2 deref x3 ∅ {r1 7→ ∅ {o1 7→ href uniti}}i [ (alloc @ hr1 , o1 i) ] − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after letregion ρ2 in let x3 = @ ρ2 href hr1 , o1 ii in @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i @ ρ2 deref x3 ∅ {r1 7→ ∅ {o1 7→ href uniti}}i [ (alloc @ hr1 , o1 i) ] − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after letregion ρ2 in let x3 = @ ρ2 href hr1 , o1 ii in @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i @ ρ2 deref x3 ∅ {r1 7→ ∅ {o1 7→ href uniti}}i [ (alloc @ hr1 , o1 i) ] − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after freeregion r2 after let x3 = @ r2 href hr1 , o1 ii in @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i @ r2 deref x3 ∅ {r1 7→ ∅ {o1 7→ href uniti}} i {r2 7→ ∅} [ (alloc @ hr1 , o1 i) ] − r2 − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after freeregion r2 after let x3 = @ r2 href hr1 , o1 ii in @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i @ r2 deref x3 ∅ {r1 7→ ∅ {o1 7→ href uniti}} i {r2 7→ ∅} [ (alloc @ hr1 , o1 i) ] − r2 − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after freeregion r2 after let x3 = hr2 , o1 i in @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i @ r2 deref x3 ∅ {r1 7→ ∅ {o1 7→ href uniti}} i {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i) ] − r2 − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after freeregion r2 after let x3 = hr2 , o1 i in @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i @ r2 deref x3 ∅ {r1 7→ ∅ {o1 7→ href uniti}} i {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i) ] − r2 − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after freeregion r2 after @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i @ r2 deref hr2 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti}} i {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i) ] − r2 − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 after freeregion r2 after @ r1 @ r1 hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i @ r2 deref hr2 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti}} i {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i) ] − r2 − r1
; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after freeregion r2 after @ r1 hr1 , o2 i @ r2 deref hr2 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i) ] − r2 − r1
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
! h freeregion r1 ; after freeregion r2 after @ r1 hr1 , o2 i @ r2 deref hr2 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i) ] − r2 − r1
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after freeregion r2 after @ r1 hr1 , o2 i hr1 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i), ] − r2 − r1 (read @ hr2 , o1 i) iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after freeregion r2 after @ r1 hr1 , o2 i hr1 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i), ] − r2 − r1 (read @ hr2 , o1 i) iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after freeregion r2 after @ r1 deref letregion ρ3 in hr1 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i), ] − r2 − r1 (read @ hr2 , o1 i), (exec @ hr1 , o2 i)
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after freeregion r2 after @ r1 deref letregion ρ3 in hr1 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i), ] − r2 − r1 (read @ hr2 , o1 i), (exec @ hr1 , o2 i)
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
! h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} {r3 7→ ∅} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i), ] − r2 − r1 (read @ hr2 , o1 i), (exec @ hr1 , o2 i) iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} {r3 7→ ∅} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i), ] − r2 − r1 (read @ hr2 , o1 i), (exec @ hr1 , o2 i) iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after freeregion r2 after @ r1 deref hr1 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i), ] − r2 − r1 (read @ hr2 , o1 i), (exec @ hr1 , o2 i)
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
! h freeregion r1 ; after freeregion r2 after @ r1 deref hr1 , o1 i } i ∅ {r1 7→ ∅ {o1 7→ href uniti} {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i), ] − r2 − r1 (read @ hr2 , o1 i), (exec @ hr1 , o2 i)
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after freeregion r2 after unit ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i), ] − r2 − r1 (read @ hr2 , o1 i), (exec @ hr1 , o2 i), (read @ hr1 , o1 i)
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after freeregion r2 after unit ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} [ (alloc @ hr1 , o1 i), (alloc @ hr1 , o2 i), ] − r1 (exec @ hr1 , o2 i), (read @ hr1 , o1 i)
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after unit ∅ {r1 7→ ∅ {o1 7→ href uniti} }i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} [ (alloc @ hr1 , o1 i), (alloc @ hr1 , o2 i), ] − r1 (exec @ hr1 , o2 i), (read @ hr1 , o1 i)
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
h freeregion r1 ; ! after unit ∅ {r1 7→ ∅ {o1 7→ href uniti} }i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} [ ]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Object Language Reduction Sequence
hunit; ∅i ! [ ]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Trees of Regions The region structure of a program is a forest So is the structure of its store
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
State Dynamics Statics Translation Enhancements
Introduction Body Summary
Trees of Regions The region structure of a program is a forest So is the structure of its store Example runr1 runr2 returnr2 runr3 returnr3 returnr1 runr4 returnr4 unit
r1 r4 r2
r3
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
State Dynamics Statics Translation Enhancements
Introduction Body Summary
Monadic Stores sr
sr
⊚s r 6 ⊚s r
∈ ::= ^ Lexical Portion holds visible region stores, as in object language ⊚s r ∈ ⊚s ǫ ::= ∅
Monadic stores in context are divided:
⊚s r
⊚s r1 r0
∈
::=
⊚s r1
r
{≬s }
Nonlexical Portion holds other region stores 6 ⊚s r 6 ⊚s r
∈
6 ⊚s ǫ 6 ⊚s r1 r0
∈
::=
fǫ .≬s
::=
fr 6 ⊚s r1 . ≬s ≬s r1 r0
f r1 ≬s
∈
f r1 ≬s
::=
f r1 r0 ≬s
Steven E. Ganz
iu-logo
Encapsulation of State with Monad Transformers
State Dynamics Statics Translation Enhancements
Introduction Body Summary
Manipulating Stores and Traces Stores
≬s
f f &(⊚s 1 {≬s 0 } ^6 ⊚s. ≬s 1 . ≬s 0 ) ≬s
0
=
f f ⊚s 6 ⊚s. ≬s ≬s 1^ 1 0
=
f f ⊚s {≬s } 6 ⊚s. ≬s . ≬s 1 0 ^ 1 0
0
f f '(⊚s 1 ^6 ⊚s. ≬s 1 ≬s 0 )
Traces &t = [f|return f ∈ t] 't = [return f|f ∈ t] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Some Monadic Language Reduction Rules
⇀ he ; s ir
⇀ he ; s ir
-run
f [] ⊚ 6 ⊚ ≬ hrun e0 ; s 1 ^ s. s 1 i ⇀
hrunning
f e0 ; ⊚s 1 ^6 ⊚s. ≬s 1 ∅i
-running [] r r 6 ⊚ ≬ ⊚ 1 0 hrunning return v0 ; s 1 ^ s. s 0 i ⇀ hreturnr1 v0 ; ⊚s 1 ^6 ⊚s. ǫi
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Some Monadic Language Evaluation Contexts
→∗ [ he; sir1 r0 ]
r1
→∗ [ tr1 r0 ]
→∗ [ he; sir1 r0 ]
r1 r0
→∗ [ tr1 r0 ]
→∗ [ he; sir1 ]
he; si ! t ∈ hrunning [ e]; &([ ⊚s] ^[ 6 ⊚s])i ! &[ t]
→∗ [ he; sir1 ]
he; si
!
t ∈
hreturn [ e]; [ ⊚s] {≬s 0 } ^[
f 6 ⊚s]. ≬s i ! '[ 0
r1
→∗ [ tr1 r0 ] r1
::=
r1 r0
→∗ [ tr1 ] r1 r0
::=
he; si !
he; si
!
t
t
t]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence hrun let x2 = href uniti in run let x3 = href x2 i in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return x2 in deref x6 in x4 x5 ∅ ^.ǫi [ ]
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence hrunning let x2 = href uniti in run let x3 = href x2 i in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return x2 in deref x6 in x4 x5 ∅ ^.∅i [ ]
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence hrunning let x2 = href uniti in run let x3 = href x2 i in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return x2 in deref x6 in x4 x5 &∅ {∅} ^.ǫ. ǫi &[ ]
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence hrunning let x2 = return o1 in run let x3 = href x2 i in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return x2 in deref x6 in x4 x5 &∅ {∅ {o1 7→ href uniti}} ^ .ǫ. ǫi &[ (alloc @ o1 ) ]
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence hrunning let x2 = return o1 in run let x3 = href x2 i in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return x2 in deref x6 in x4 x5 &∅ {∅ {o1 7→ href uniti}} ^ .ǫ. ǫi &[ (alloc @ o1 ) ]
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning run let x3 = href o1 i in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 x5 &∅ {∅ {o1 7→ href uniti}} ^ .ǫ. ǫi &[ (alloc @ o1 ) ]
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning run let x3 = href o1 i in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 x5 &∅ {∅ {o1 7→ href uniti}} ^ .ǫ. ǫi &[ (alloc @ o1 ) ]
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running let x3 = href o1 i in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 x5 &∅ {∅ {o1 7→ href uniti}} ^ .ǫ. ∅i &[ (alloc @ o1 ) ]
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running let x3 = href o1 i in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 x5 &&∅ {∅ {o1 7→ href uniti}} {∅} ^.ǫ. ǫ. ǫi &([ (alloc @ o1 ) ] + &[ ])
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running let x3 = return return o1 in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 x5 &&∅ {∅ {o1 7→ href uniti}} {∅ {o1 7→ href o1 i}} ^.ǫ. ǫ. ǫi &([ (alloc @ o1 ) ] + &[ (alloc @ o1 ) ])
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running let x3 = return return o1 in let x5 = deref x3 in return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 x5 &&∅ {∅ {o1 7→ href uniti}} {∅ {o1 7→ href o1 i}} ^.ǫ. ǫ. ǫi &([ (alloc @ o1 ) ] + &[ (alloc @ o1 ) ])
; !
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running let x5 = deref o1 in return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 x5 &&∅ {∅ {o1 7→ href uniti}} {∅ {o1 7→ href o1 i}} ^.ǫ. ǫ. ǫi &([ (alloc @ o1 ) ] + &[ (alloc @ o1 ) ])
; ! i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running let x5 = deref o1 in return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 x5 &&∅ {∅ {o1 7→ href uniti}} {∅ {o1 7→ href o1 i}} ^.ǫ. ǫ. ǫi &([ (alloc @ o1 ) ] + &[ (alloc @ o1 ) ])
; ! i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running let x5 = return return o1 in return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 x5 &&∅ {∅ {o1 7→ href uniti}} {∅ {o1 7→ href o1 i}} ^.ǫ. ǫ. ǫi &([ (alloc @ o1 ) ] + &[ (alloc @ o1 ), (read @ o1 ) ])
; ! i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running let x5 = return return o1 in return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 x5 &&∅ {∅ {o1 7→ href uniti}} {∅ {o1 7→ href o1 i}} ^.ǫ. ǫ. ǫi &([ (alloc @ o1 ) ] + &[ (alloc @ o1 ), (read @ o1 ) ])
; ! i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 o1 &&∅ {∅ {o1 7→ href uniti}} {∅ {o1 7→ href o1 i}} ^.ǫ. ǫ. ǫi &([ (alloc @ o1 ) ] + &[ (alloc @ o1 ), (read @ o1 ) ])
i ; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running return let x4 = hλx1 .let x6 = run return return o1 in deref x6 in x4 o1 &&∅ {∅ {o1 7→ href uniti}} {∅ {o1 7→ href o1 i}} ^.ǫ. ǫ. ǫi &([ (alloc @ o1 ) ] + &([ (alloc @ o1 ), (read @ o1 ) ] + '[]))
i ; !
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
! hrunning running return let x4 = return o2 ; in x4 o1 } ^ .ǫ. ǫ. ǫi && ∅ {∅ {o1 7→ href uniti} i} {o2 7→ hλx1 .let x6 = run return return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
! hrunning running return let x4 = return o2 ; in x4 o1 && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ǫ. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running return o2 o1 ; ! } ^ .ǫ. ǫ. ǫi && ∅ {∅ {o1 7→ href uniti} i} {o2 7→ hλx1 .let x6 = run return return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ) ]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence ! hrunning running return let x6 = run return ; return o1 in deref x6 && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ǫ. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ), (exec @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence ! hrunning running return let x6 = run return ; return o1 in deref x6 && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ǫ. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ), (exec @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence ! hrunning running return let x6 = running return ; return o1 in deref x6 && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ∅. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ), (exec @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence ! hrunning running return let x6 = running return ; return o1 in deref x6 && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ∅. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &[ (alloc @ o1 ), (read @ o1 ), ]) return (alloc @ o2 ), return (exec @ o2 ) iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running return let x6 = running return ; ! return o1 in deref x6 } i & ∅ {∅ {o1 7→ href uniti} i} {o2 7→ hλx1 .let x6 = run return return o1 in deref x6 ˆ.ǫ. ∅ ∅ {o1 7→ href o1 i} &[ (alloc @ o1 ), (alloc @ o2 ), (exec @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
! hrunning running return let x6 = running return ; return o1 in deref x6 ∅ ^.∅ {o1 7→ href uniti} i {o2 7→ hλx1 .let x6 = run return return o1 in deref x6 i} ∅
∅ {o1 7→ href o1 i}
[ ]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running return let x6 = running return ; ! return o1 in deref x6 } i & ∅ {∅ {o1 7→ href uniti} i} {o2 7→ hλx1 .let x6 = run return return o1 in deref x6 ˆ.ǫ. ∅ ∅ {o1 7→ href o1 i} &[ (alloc @ o1 ), (alloc @ o2 ), (exec @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence ! hrunning running return let x6 = running return ; return o1 in deref x6 && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ∅. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &[ (alloc @ o1 ), (read @ o1 ), ]) return (alloc @ o2 ), return (exec @ o2 ) iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence ! hrunning running return let x6 = running return ; return o1 in deref x6 && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ∅. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ), (exec @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence ! hrunning running return let x6 = running return ; return o1 in deref x6 && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ∅. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ), (exec @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
! hrunning running return let x6 = return o1 ; in deref x6 && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ǫ. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ), (exec @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
! hrunning running return let x6 = return o1 ; in deref x6 && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ǫ. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ), (exec @ o2 ) ] iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running return deref o1 ; ! && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ǫ. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ), (exec @ o2 ) ]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running return deref o1 ; ! && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ǫ. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ )) '[ (alloc @ o2 ), (exec @ o2 ) ]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running return return unit; ! && ∅ {∅ {o1 7→ href uniti} } ^ .ǫ. ǫ. ǫi {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 {∅ {o1 7→ href o1 i}} )) &([ (alloc @ o1 ) ] + &( [ (alloc @ o1 ), (read @ o1 ) ]+ '[ (alloc @ o2 ), (exec @ o2 ), (read @ o1 ) ]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
! hrunning running return return unit; } ^ .ǫ. ǫ. ǫi && ∅ {∅ {o1 7→ href uniti} i} {o2 7→ hλx1 .let x6 = run return return o1 in deref x6 {∅ {o1 7→ href o1 i}} &( [ (alloc @ o1 ) ]+ ) &([ (alloc @ o1 ), (read @ o1 ), return (alloc @ o2 ), ]) return (exec @ o2 ), return (read @ o1 ) iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning running return return unit; ! & ∅ {∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 ˆ.ǫ. ∅ {o1 7→ href o1 i} &[ (alloc @ o1 ), (alloc @ o2 ), (exec @ o2 ), (read @ o1 ) ]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning return unit; ! & ∅ {∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .let x6 = run return i} return o1 in deref x6 ˆ.ǫ. ǫ &[ (alloc @ o1 ), (alloc @ o2 ), (exec @ o2 ), (read @ o1 ) ]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hrunning return unit; ∅ ^.∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x6 = run return return o1 in deref x6 [ ]
! i i}
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Monadic Language Reduction Sequence
hunit; ∅ ^.ǫi ! [ ]
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Some Object Language Definitions Γ ρ1 ρ2 − ρ2 Γ {ρ0 } − ρ2 ρ0 Γ {x 7→ P} − ρ2 Γ − ǫ
∈ Γ ρ1 = Γ − ρ2 = (Γ − ρ2 ) {x 7→ (P − ρ2 )} = Γ
P ρ1 ρ2 − ρ2 G − ρ2 ∅ − ρ2 (B0 @ ρ0 ) − ρ21 ρ0 ρ22 (ρ0 ∈ / ρ2 ) (B0 @ ρ0 ) − ρ2
∈ = = = =
P ρ1 G ∅ ∅ B0 @ ρ0 iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
State Dynamics Statics Translation Enhancements
Introduction Body Summary
Some Object Language Typing Rules ⊢ v-addr-live
⊢ v-addr-dead
⊢ e-letregion
⊢ e-freeregion
a0 = hr0 , oi S
S
r1 r0 ̺2 v ⊢
̺ v ⊢
a0 : S( a0 ) @ r0
h∅, oi : ∅ Γ1 {ρ0 }; S
Γ1 ; S
⊢ e-pure
̺1 e ⊢
̺1 ρ0 e ⊢
Γ1 ; S
Γ; S
̺ p ⊢
̺ e ⊢
p: P
p: P!∅
e0 : P0 ! T0
letregion ρ0 in e0 : P0 − ρ0 ! T0 − ρ0 Γ1 {r0 }; S
r1 e ⊢
Γ;
|S|̺
r1 r0 e ⊢
e0 : P0 ! T0
freeregion r0 after e0 : P0 − r0 ! T0 − r0 iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Some Monadic Language Definitions
≬Γ ρ1
ρ1 ρ0
ρ1
2ρ1 ρ0 ≬Γ ≬Γ 2ρ1 ρ0 ∅ 1 ≬Γ 2ρ1 ρ0 ≬Γ {x → 7 P} 1 2
∈ ≬Γ = ≬Γ 1 = (≬Γ 1 2ρ1 ρ0 ≬Γ 2 ) {x 7→ P :=ρ1 ρ0 ∅}
P ρ1 ρ0 :=ρ1 ρ0 ∅ B :=ρ1 ρ0 ∅ Return B :=ρ1 ρ0 ∅
∈ P ρ1 = Returnρ1 ∅ = B
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Some Monadic Language Typing Rules ⊢ v-addr-live
⊢ v-ret-run
⊚S
⊚S ⊚S
⊢ v-ret-running
⊢ e-pure
r1 r0 v ⊢
{≬S}
̺ v ⊢
̺ρ0 v ⊢
1
o: ∅
v : Return P1
{≬S Γ;
∅
ǫ v ⊢
v : P1
⊚S ⊚S
o:
≬S( o)
⊢ v-addr-dead
0}
⊚S
Γ; ⊚S ^6 ⊚S ⊢ e
̺
1
r1 v ⊢ r1 r0 v ⊢
̺ p ⊢
v : P1 v : Return P1 p: P
return̺ p : St∅ Id P Steven E. Ganz
Encapsulation of State with Monad Transformers
iu-logo
State Dynamics Statics Translation Enhancements
Introduction Body Summary
Some More Monadic Language Typing Rules ⊢ e-run
Γ1 {∅}; S1 ⊢ e Γ1 ; S1 ⊢ e
run e0 : T1 P0 :=̺1 ρ0 ∅
Γ1 {∅}; 'S1
⊢ e-running
⊢ e-ret-run
̺1
Γ1 ; S1
r1 e ⊢
Γ Γ
{≬Γ
1
e0 : ≬T 0 T1 P0
̺1 ρ0
} {≬Γ
r1 r0 e ⊢
e0 : ≬T 0 T1 P0
running e0 : T1 P0 :=r1 r0 ∅ {≬Γ
1
2
0 }; S1
≬Γ
0 };
̺1 ρ0 e ⊢
S1
̺1 e ⊢
e1 : T1 P1
return e1 : St∅ T1 (Return P1 ) r
Γ {≬Γ 1 2 ≬Γ 0 }; ⊚S 1 ^ 6 ⊚S 1 ⊢ e 1 e1 : T1 P1
⊢ e-ret-running Γ
{≬Γ
1
} {≬Γ
0 };
f ⊚S {≬S } 6 ⊚S . ≬S 1 1 0 ^ 0 Steven E. Ganz
r1 r0 e ⊢
return e1 : St∅ T1 (Return P1 )iu-logo
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Some Dynamic Translation Clauses r N he; si si]]
[he; ̺1 N e [letregion ρ0 in e0] r1 N e [freeregion r0 after e0] ̺N e [p]] ̺ [let x = e1 in e2] e N ̺ = ̺1 ̺0 ̺2 N [@ ̺0 href ei]] e r r ̺ [hr0 , oi]] v 1 0 2 N [h∅, oi]] v r r [s]] s ^ 3 N ǫ [∅]] s N
̺N
[s1 {r0 7→ r [t]] t N
≬s
= = = = = = =
rN e h[[e]] ;
r s [s]]
^ Dom( s) − r N
i
̺1 ρ0 e N run [e0] r1 r0 N e running [e0] ̺N ̺ p return [p]]
let x = [e1] e N in [e2] e N ̺ let x = [e]] e N in return̺2 href xi o ̺
̺
= o rr = &r3 ([[s]] s 3 N ^ .ǫ. ǫ. ǫ) = ∅ 0
r r }]] s 1 0 N
r ]s 1N
{[[≬s
≬s r1 r0 N
} = [s1 0] = [returnr2 (ι @ o)|r = r1 r0 r2 ∧ ] iu-logo (ι @ hr0 , oi) ∈ t Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} {r3 7→ ∅}
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i ∅ {r1 7→ ∅ {o1 7→ href uniti} } i {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} {r3 7→ ∅}
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {r1 7→ ∅ {o1 7→ href uniti} {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} {r3 7→ ∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
)i
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {r1 7→ ∅ {o1 7→ href uniti} {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
)i
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {r1 7→ ∅ {o1 7→ href uniti} {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {r2 7→ ∅ {o1 7→ href hr1 , o1 ii}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
)i
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {r1 7→ ∅ {o1 7→ href uniti} {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {∅ {o1 7→ href hr1 , o1 ii}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
)i
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {r1 7→ ∅ {o1 7→ href uniti} {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {∅ {o1 7→ href hr1 , o1 ii}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
)i
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {r1 7→ ∅ {o1 7→ href uniti} {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {∅ {o1 7→ href hr1 , o1 ii}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
)i
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {r1 7→ ∅ {o1 7→ href uniti} {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
)i
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {r1 7→ ∅ {o1 7→ href uniti} {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
)i
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i &&&( ∅ {∅ {o1 7→ href uniti} } {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i &&&( ∅ {∅ {o1 7→ href uniti} } {o2 7→ hλx1 .@ r1 deref letregion ρ3 in hr1 , o1 i i} {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i &&&( ∅ {∅ {o1 7→ href uniti} } {o2 7→ hλx1 .let x2 = letregion ρ3 in hr1 , o1 i in deref x2 i} {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
)
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } )i &&&( ∅ {∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run hr1 , o1 i i} in deref x2 {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } &&&( ∅ {∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i &&&( ∅ {∅ {o1 7→ href uniti} } {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 {∅ {o1 7→ href o1 i}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i } )i &&( ∅ {∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 {∅ {o1 7→ href o1 i}} ˆ.ǫ. ǫ. ∅
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration
h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i &(∅ {∅ {o1 7→ href uniti} } )i {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 ˆ.ǫ. ∅ {o1 7→ href o1 i} | ∅ iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration h freeregion r1 ; after freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i i ∅ ˆ. ∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 | ∅ {o1 7→ href o1 i} | ∅ iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration h running ; freeregion r2 after @ r1 deref freeregion r3 after hr1 , o1 i ∅ ˆ. ∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 | ∅ {o1 7→ href o1 i} | ∅
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration h running ; running @ r1 deref freeregion r3 after hr1 , o1 i ∅ ˆ. ∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 | ∅ {o1 7→ href o1 i} | ∅
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration ; h running running let x3 = freeregion r3 after hr1 , o1 i in return deref x3 ∅ ˆ. ∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 | ∅ {o1 7→ href o1 i} | ∅
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration ; h running running let x3 = running hr1 , o1 i in return deref x3 ∅ ˆ. ∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 | ∅ {o1 7→ href o1 i} | ∅
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Configuration ; h running running let x3 = running return return o1 in return deref x3 ∅ ˆ. ∅ {o1 7→ href uniti} {o2 7→ hλx1 .let x2 = run return return o1 i} in deref x2 | ∅ {o1 7→ href o1 i} | ∅
i
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Dynamic Translation on Trace
r
[[ (alloc @ hr1 , o1 i), (alloc @ hr2 , o1 i), (alloc @ hr1 , o2 i), ]]]t 1 N = (read @ hr2 , o1 i), (exec @ hr1 , o2 i) [ return (alloc @ o1 ), (alloc @ o1 ), return (alloc @ o2 ), ] (read @ o1 ), return (exec @ o2 )
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
State Dynamics Statics Translation Enhancements
Introduction Body Summary
Some Static Translation Clauses r hE; Si N Si]]
[hE;
[P ! T]] E
̺
N
r
= h[[E]] E N; [S]] S = [T]] T
̺
r ^ Dom( S) − r N
i
N [P]] P̺ N
[T]] T 0 N ǫ [T]] T N
= St{ι|(ι @ ̺0 ) ∈ T} [T − ̺0] T = Id
̺ P [G]] N
= Return̺ G
̺̺
[B @ ̺0] P [∅]] P r
̺
̺1 ̺0 ̺2
N
N
[S]] S 0 ^ ǫ S [∅]] N
̺1 ̺0
N
N
= Return̺ ∅
r3 N
[S {r0 7→
= Return̺2 [B]] B
̺
r r3 N
= &r3 ([[S]] S 0 = ∅ ≬S}]] S r1 r0 N
=
r1 S [S]] N
^ .ǫ. ǫ. ǫ)
≬S ≬ {[[ S]]
r1 r0 N
} iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
} i {(read @ r1 )}
{o2 7→ Ref Unit @ r1 ⇒ {r2 7→ ∅ {o1 7→ Ref (Ref Unit @ r1 )}} {r3 7→ ∅}
Ref Unit @ r1 }
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
} i {(read @ r1 )}
{o2 7→ Ref Unit @ r1 ⇒ {r2 7→ ∅ {o1 7→ Ref (Ref Unit @ r1 )}} {r3 7→ ∅}
Ref Unit @ r1 }
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
} {(read @ r1 )}
⇒ {o2 7→ Ref Unit @ r1 {r2 7→ ∅ {o1 7→ Ref (Ref Unit @ r1 )}} {r3 7→ ∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
Ref Unit @ r1 }
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
} {(read @ r1 )}
⇒ {o2 7→ Ref Unit @ r1 {r2 7→ ∅ {o1 7→ Ref (Ref Unit @ r1 )}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
Ref Unit @ r1 }
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
} {(read @ r1 )}
⇒ {o2 7→ Ref Unit @ r1 {r2 7→ ∅ {o1 7→ Ref (Ref Unit @ r1 )}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
)i
Ref Unit @ r1 }
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
} {(read @ r1 )}
{o2 7→ Ref Unit @ r1 {∅ {o1 → 7 Ref (Ref Unit @ r1 )}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
⇒
)i
Ref Unit @ r1 }
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
} {(read @ r1 )}
{o2 7→ Ref Unit @ r1 {∅ {o1 → 7 Ref (Ref Unit @ r1 )}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
⇒
)i
Ref Unit @ r1 }
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
} {(read @ r1 )}
{o2 7→ Ref Unit @ r1 {∅ {o1 → 7 Ref (Ref Unit @ r1 )}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
⇒
)i
Ref Unit @ r1 }
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
} {(read @ r1 )}
{o2 7→ Ref Unit @ r1 {∅ {o1 → 7 Ref Return Ref Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
⇒
)i
Ref Unit @ r1 }
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
} {(read @ r1 )}
{o2 7→ Ref Unit @ r1 {∅ {o1 → 7 Ref Return Ref Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
⇒
)i
Ref Unit @ r1 }
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
⇒ Ref Unit @ r1 } {o2 7→ Ref Unit @ r1 {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {r1 7→ ∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
⇒ Ref Unit @ r1 } {o2 7→ Ref Unit @ r1 {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
⇒ Ref Unit @ r1 } {o2 7→ Ref Unit @ r1 {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
{o2 7→ Ref Unit @ r1 ⇒ Ref Unit @ r1 } {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
{o2 7→ Ref Unit @ r1 ⇒ Ref Unit @ r1 } {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
{o2 7→ Ref Unit ⇒ Ref Unit @ r1 } {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
{o2 7→ Ref Unit ⇒ Ref Unit @ r1 } {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
{o2 7→ Ref Return Unit ⇒ Ref Unit @ r1 } {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
{o2 7→ Ref Return Unit ⇒ Ref Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
{o2 7→ Ref Return Unit ⇒ Ref Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{(read @ r1 )}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Unit}
}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Return Unit}
}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Return Unit}
}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&&( ∅ {∅ {o1 7→ Ref Return Unit}
}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} {∅} ˆ.ǫ. ǫ. ǫ. ǫ
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
State Dynamics Statics Translation Enhancements
Introduction Body Summary
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &&( ∅ {∅ {o1 7→ Ref Return Unit}
} )i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} {∅ {o1 7→ Ref Return Ref Return Unit}} ˆ.ǫ. ǫ. ∅
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; &(∅ {∅ {o1 7→ Ref Return Unit}
} )i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} ˆ.ǫ. ∅ {o1 7→ Ref Return Ref Return Unit} | ∅
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hUnit ! {(read @ r1 )}; (∅ ˆ. ∅ {o1 7→ Ref Return Unit}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} | ∅ {o1 7→ Ref Return Ref Return Unit} | ∅
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
h{(read @ r1 )} Unit; (∅ ˆ. ∅ {o1 7→ Ref Return Unit}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} | ∅ {o1 7→ Ref Return Ref Return Unit} | ∅
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hSt{} {(read @ r1 )} Unit; (∅ ˆ. ∅ {o1 7→ Ref Return Unit}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} | ∅ {o1 7→ Ref Return Ref Return Unit} | ∅
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hSt{} St{} {(read @ r1 )} Unit; (∅ ˆ. ∅ {o1 7→ Ref Return Unit}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} | ∅ {o1 7→ Ref Return Ref Return Unit} | ∅
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hSt{} St{} St{read} {} Unit; (∅ ˆ. ∅ {o1 7→ Ref Return Unit}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} | ∅ {o1 7→ Ref Return Ref Return Unit} | ∅
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hSt{} St{} St{read} Id Unit; (∅ ˆ. ∅ {o1 7→ Ref Return Unit}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} | ∅ {o1 7→ Ref Return Ref Return Unit} | ∅
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Example of Static Translation on Configuration Type
hSt{} St{} St{read} Id Return Return Return Unit; (∅ ˆ. ∅ {o1 7→ Ref Return Unit}
)i
{read}
{o2 7→ Ref Return Unit ⇒ Ref Return Unit} | ∅ {o1 7→ Ref Return Ref Return Unit} | ∅
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Lack of Preservation of Information Content Object language store is linear, monadic is tree-shaped Monadic evaluation carries more info, better incorporates our restricted store Incorporates the fact that a function allocated in an outer region does not have access to the full store Our translation cannot catch up. Thus, the earlier you translate, the better. iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Recursion
Simple unfolding is not appropriate – only allocate once! Convert recursive function to a nonrecursive one. Take advantage of the recursion inherent in our region stores.
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Polymorphism
Use ML-style let-based polymoriphism on storable types Divide expressions by whether generalizable Environment is polymorphic Region store types and judgements for storables are polymorphic to preserve type soundness
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Eager Deallocation Why not deallocate as soon as you know a region won’t be used? Ideally: Use effect system to ensure safety A simpler approach: Deallocate region when not actively mentioned Must remove region not just in values but expressions Must generalize rules for store processing on region deallocation iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Eager Deallocation Reduction Rules Object Language ⇀ he ; s i
he0 ; s2 inot actively mentioningr0
-freeregion [] hfreeregion r0 after e0 ; s1 {r0 7→ ≬s 0 } s2 i ⇀ he0 [ r0 := ∅]; s1 s2 [ r0 := ∅]i Monadic Language
⇀ he ; s i
-running
f e0 , ≬s 0
not actively mentioning the current region ≬s
hrunning e0 ; ⊚s 1 ^ 6 ⊚s.
0
f f [] ≬s ≬s i ⇀ 0 1
he0 := ∅;
f ⊚s 6 ⊚s. (≬s 1^ 0
:=
f ∅) ≬s 1 i iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Incremental Implementation
Second translation to a functional implementation Incremental implementation – outermost regions first. Partially implemented programs considered runnable. Prior monad applied to pair of region store type and result value type; bind makes the region store available for implemented regions.
iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
State Dynamics Statics Translation Enhancements
Monadic Reflection Reflection: reify makes an implementation data structure available at runtime reflect installs a user-generated data structure into the runtime implementation Monadic Reflection: Implementation data structures are functional representations of monadic code reflect and reify can be used to abstract over operations provided by a monad An opportunity for monadic reflection: cease incremental implementation on reflect, resume on reify Steven E. Ganz
Encapsulation of State with Monad Transformers
iu-logo
Introduction Body Summary
Some References Monad Transformers (Moggi, 1990) Effects and Encapsulation (Tofte & Talpin, 1994) Nonpermeable Encapsulation via Monads (Launchbury & Peyton Jones, 1995) Monads and Effects (Wadler, 1998) Monads and Effects, Nonpermeable Encapsulation (Semmelroth & Sabry, 1999), (Moggi & Palumbo, 1999), (Moggi & Sabry, 2001) Encapsulation via Family of Monads (Fluet & Morrisett, 2004) Encapsulation of Continuations (Dybvig, Jones, & Sabry, 2005) iu-logo
Steven E. Ganz
Encapsulation of State with Monad Transformers
Introduction Body Summary
Summary Monad transformers allow for representing encapsulated effects with interaction between computations at different regions. Neither our dynamic nor static syntax mention region indicators, so the meaning of a program is independent of region names. The region structure of a monadic program supporting only outward references, and thus the store of such a program with state effects, is best represented as a sequence of trees. This tree structure carries information not available to a direct-style program with a linear store – namely that certain regions are not accessible. Steven E. Ganz
Encapsulation of State with Monad Transformers
iu-logo