the Effect? • Example: Memory-state effect 2. Koka • Effect in Koka • Syntax in Koka • Some details 3. Effect as Parametric Monad • Structures in Effects • Monads and Effects 3
the Effect? • Example: Memory-state effect 2. Koka • Effect in Koka • Syntax in Koka • Some details 3. Effect as Parametric Monad • Structures in Effects • Monads and Effects 4
(or an effect product). Me1 1 , Me2 2 : A × B ! e1 · e2 let x = Me1 in Ne2 : B ! e1 · e2 Observation: effects can be stacked We will discuss the others later. 7
the Effect? • Example: Memory-state effect 2. Koka • Effect in Koka • Syntax in Koka • Some details 3. Effect as Parametric Monad • Structures in Effects • Monads and Effects 10
Koka is a function-oriented programming language that seperates pure values from side-effecting computations, where the effect of every function is automatically inferred. 11
the Effect? • Example: Memory-state effect 2. Koka • Effect in Koka • Syntax in Koka • Some details 3. Effect as Parametric Monad • Structures in Effects • Monads and Effects 20
“Parametric” computation. =⇒ So does the laws? Monad laws: • (assoc) (let x = M in (let y = N in L)) ≡ (let y = (let x = M in N) in L • (left id) (let x = x in M) ≡ M • (right id) (let x = M in x) ≡ M 22
Me) ≡ Me, we should assume: • Variable x has no effect, namely ∅ • Right-hand side, the effect is e • Left-hand side, the effect should be ∅ · e We should have left identity law of effect: ∅ · e = e 23
Have an unit ∅ ∈ E • Have a binary operator (·) : E × E → E • E, (·), ∅ is a monoid • Have a preorder (≤) ⊆ E × E • The (monoid/preorder) operators are compatible 25
the address set J might be modified from the initial state. TI (A) = ∀J ∈ P(Addr). Mem(J) → (Mem(I ∪ J) × A) Interpret Γ M : A ! e as M : Γ → Te (A) • readi : 1 → T{i}nat • writei : nat → T{i} 1 28
(List(A) ??? − → List(B)) Simple idea Introduce (possibly many-times) multiplied effect, e†. Then, how do we give the semantics of the fixpoint? mfix : (A e − → A) e† − → A 31
Types” • Shin-ya Katsumata. 2014. “Parametric effect monads and semantics of effect systems” • Andrej Bauer and Matija Pretnar. 2012. “Programming with Algebraic Effects and Handlers” • Sam Lindley, Conor McBride, Craig McLaughlin. 2016. “Do Be Do Be Do” 32