The Sequential Semantics of Producer Effect Systems
description
Transcript of The Sequential Semantics of Producer Effect Systems
THESEQUENTIAL SEMANTICS OFPRODUCER EFFECT SYSTEMS
Ross Tate
THESEQUENTIAL SEMANTICS OFPRODUCER EFFECT SYSTEMS
Ross Tate
WHAT IS AN EFFECT?Output
s
Inputs Computation
Types
IgnoresInputs
LeaksInformatio
n ThrowsException
THESEQUENTIAL SEMANTICS OFPRODUCER EFFECT SYSTEMS
Ross Tate
EFFECT SYSTEM FOR LOCKING
acquire
acquire
lockinglocking
get release
unlockingcriticalacquire
locking }entrant
WHAT IS AN EFFECT SYSTEM?
lockless locking unlocking critical entrant↓ ; →
lockless
lockingunlocki
ngcritical
entrant
lockless locking unlocking critical entrant
locking entrant lockingunlockin
g critical unlocking
critical unlocking critical
entrant locking entrant
EFFECTS FOR PURE CODE
÷ 2
locklesscritical entrant
locking unlocking
“May” Properti
es
“Must” Properti
es
WHAT IS AN EFFECT SYSTEM?
Cannot be formalized semantically
by any preexisting framework
e ↦ lockless, critical, entrantlockless ≤ critical, entrant
lockless locking unlocking critical entrant↓ ; →
lockless locking unlocking critical entrantlockles
slocking entrant lockinglocking
unlocking critical unlockin
gunlocki
ngcritical unlockin
g criticalcriticalentrant locking entrantentrant
WHAT IS AN EFFECT SYSTEM?
Monade ↦ lockless, critical, entrant
lockless↓ ; →locklesslockles
s
WHAT IS AN EFFECT SYSTEM?
Indexed Monade ↦ lockless, critical, entrant
lockless ≤ critical, entrant
lockless entrant↓ ; →lockless entrantlockles
s
entrant entrantentrant
WHAT IS AN EFFECT SYSTEM?
Layered Monads in Action
e ↦ lockless, critical, entrantlockless ≤ critical, entrant
lockless critical entrant↓ ; →lockless critical entrantlockles
s
critical criticalcriticalentrant entrantentrant
Monads cannot be used for “must”
properties.
WHAT IS AN EFFECT SYSTEM?
Parameterized Monade ↦ lockless, critical, entrant
locking unlocking critical entrant↓ ; →
entrant lockinglockingcritical unlockin
gunlocki
ng unlocking criticalcritical
locking entrantentrant
WHAT IS AN EFFECT SYSTEM?
e ↦ lockless, critical, entrantlockless ≤ critical, entrant
Productoid
lockless locking unlocking critical entrant↓ ; →
lockless locking unlocking critical entrantlockles
slocking entrant lockinglocking
unlocking critical unlockin
gunlocki
ngcritical unlockin
g criticalcriticalentrant locking entrantentrant
THESEQUENTIAL SEMANTICS OFPRODUCER EFFECT SYSTEMS
Ross Tate
Pε
WHAT IS A PRODUCER EFFECT?
τ’τ ετ’τ
⟦⟧
partial
May
be
LOCKING-EFFECT PRODUCTIONS Plockless(τ) = Pe(τ) Plocking(τ)= L ⊸ Pe(C ⨂ τ) Punlocking(τ) = C ⊸ Pe(L ⨂ τ) Pcritical(τ) = C ⊸ Pe(C ⨂ τ) Pentrant(τ)= L ⊸ Pe(L ⨂ τ)
Abstract Types
THESEQUENTIAL SEMANTICS OFPRODUCER EFFECT SYSTEMS
Ross Tate
}C⊸C ⊗C⊸C ⊗
SEQUENCING EFFECTFUL WITH PURE
ℤ1 getcritical ÷ 2 ℝ
ℤ1 ℝ⟦⟧ ma
p
critical
Expects an ℤProduces a C⊸C⊗ℤ
SEQUCENCING EFFECTFUL TOGETHER }⟦⟧⟦⟧
ε''
mapjoin
ℤ ℕℝ ℤ ℕ
Pεℝ ℤ ℕ
ε ε'
ℕPε’
Pε
Pε’’
ε ; ε’ ↦ ε’’Pε’
Monadneedsε=ε’=ε
’’
WHAT IS A PRODUCTOID? For each ε: For each ε ; ε’ ↦ ε’’: For each ε ≤ ε’: For each e ↦ ε:
τ τ’ τ τ’map PεPεjoin
Pε’’τ τPε’Pε
coerce Pε’τ τPε
unit Pετ τ
Propagate effects
Sequence effects
Impurify into effects
Convert effects
GENERALITYThe sequential semantics
of any producer effect system forms a productor.
Any effectful language that canthunk computations into pure
valueshas only producer effects.
PRODUCTORS BUILT FROM … a single effect
are monads [Moggi] a join semi-lattice of effects
are indexed monads [Wadler & Thiemann] a partial join semi-lattice of effects
are layered monads in action [Filinski] a state-transition effect system
are parameterized monads [Atkey]These are all if and only
ifs.
APPLYING PRODUCTORSAbstract Operations:
acquire : L ⊸ C release : C ⊸ L get : C ⊸ C ⨂ ℤ set : C ⨂ ℤ ⊸ C
Productor using linear type theory ensures:shared memory accessed only in critical regionsno deadlocks possible
lockingunlockingcriticalcritical
LOCKLESS EFFECTS Linear Strength
α ⨂ Pe(τ) ⊸ Pe(α ⨂ τ) lockless cannot include
exceptions
WHAT IS A PRODUCTOID? For each ε: For each ε ; ε’ ↦ ε’’: For each ε ≤ ε’: For each e ↦ ε:
τ τ’ τ τ’map PεPεjoin
Pε’’τ τPε’Pε
coerce Pε’τ τPε
unit Pετ τ
WHAT IS A PRODUCTOR? For each ε1 ; … ; εn ↦ ε: For each ε ; ε’ ↦ ε’’: For each ε ≤ ε’: For each e ↦ ε:
joinPε’’τ τPε’Pε
coerce Pε’τ τPε
unit Pετ τ
join Pετ τPnP1 …
WHAT IS A PRODUCTOR?
Pε1 Pεi Pεm Pεn… … … τjoin
join…
join…P �̂� P~𝜀 τPε τ
join
Pε τ
CONCLUSION Formalized sequential structure of
Effects: effectorsSemantics: productors
Proved generality/applicability of productorsAll producer effect systemsThunking guarantees producer effects
Opportunities for future researchConsumer effects: how are inputs used?Consumptors: dualize productors ?