Effect systems revisited control-flow algebra and semantics (slides) - - PowerPoint PPT Presentation

effect systems revisited
SMART_READER_LITE
LIVE PREVIEW

Effect systems revisited control-flow algebra and semantics (slides) - - PowerPoint PPT Presentation

Effect systems revisited control-flow algebra and semantics (slides) Nielson-Nielson Festschrift 2016 Alan Mycroft 1 Dominic Orchard 1 , 2 Tomas Petricek 1 1 University of Cambridge 2 Imperial College London 1 / 20 Simple set-based effects `


slide-1
SLIDE 1

Effect systems revisited – control-flow algebra and semantics (slides)

Nielson-Nielson Festschrift 2016 Alan Mycroft1 Dominic Orchard1,2 Tomas Petricek1

1University of Cambridge 2Imperial College London 1 / 20

slide-2
SLIDE 2

Simple set-based effects `

a la (Gifford, Lucassen 1986)

Γ ⊢ e : τ, Φ

2 / 20

slide-3
SLIDE 3

Simple set-based effects `

a la (Gifford, Lucassen 1986)

Γ ⊢ e : τ, Φ

(play) Γ ⊢ play(N, L) : void, {N}

2 / 20

slide-4
SLIDE 4

Simple set-based effects `

a la (Gifford, Lucassen 1986)

Γ ⊢ e : τ, Φ

(play) Γ ⊢ play(N, L) : void, {N} (if) Γ ⊢ e0 : bool, Φ0

Γ ⊢ e1 : τ, Φ1 Γ ⊢ e2 : τ, Φ2 Γ ⊢ if e0 then e1 else e2 : τ, Φ0 ∪ Φ1 ∪ Φ2

2 / 20

slide-5
SLIDE 5

Simple set-based effects `

a la (Gifford, Lucassen 1986)

Γ ⊢ e : τ, Φ

(play) Γ ⊢ play(N, L) : void, {N} (if) Γ ⊢ e0 : bool, Φ0

Γ ⊢ e1 : τ, Φ1 Γ ⊢ e2 : τ, Φ2 Γ ⊢ if e0 then e1 else e2 : τ, Φ0 ∪ Φ1 ∪ Φ2

(seq) Γ ⊢ e1 : τ1, Φ1

Γ ⊢ e2 : τ2, Φ2 Γ ⊢ e1; e2 : τ2, Φ1 ∪ Φ2

2 / 20

slide-6
SLIDE 6

Simple set-based effects `

a la (Gifford, Lucassen 1986)

Γ ⊢ e : τ, Φ

(play) Γ ⊢ play(N, L) : void, {N} (if) Γ ⊢ e0 : bool, Φ0

Γ ⊢ e1 : τ, Φ1 Γ ⊢ e2 : τ, Φ2 Γ ⊢ if e0 then e1 else e2 : τ, Φ0 ∪ Φ1 ∪ Φ2

(seq) Γ ⊢ e1 : τ1, Φ1

Γ ⊢ e2 : τ2, Φ2 Γ ⊢ e1; e2 : τ2, Φ1 ∪ Φ2

(for)

Γ ⊢ e : void, Φ Γ ⊢ for i = n1 to n2 do e : void, Φ

2 / 20

slide-7
SLIDE 7

Simple set-based effects `

a la (Gifford, Lucassen 1986)

Γ ⊢ e : τ, Φ

(play) Γ ⊢ play(N, L) : void, {N} (if) Γ ⊢ e0 : bool, Φ0

Γ ⊢ e1 : τ, Φ1 Γ ⊢ e2 : τ, Φ2 Γ ⊢ if e0 then e1 else e2 : τ, Φ0 ∪ Φ1 ∪ Φ2

(seq) Γ ⊢ e1 : τ1, Φ1

Γ ⊢ e2 : τ2, Φ2 Γ ⊢ e1; e2 : τ2, Φ1 ∪ Φ2

(for)

Γ ⊢ e : void, Φ Γ ⊢ for i = n1 to n2 do e : void, Φ for our example we get {G3, F3, A3, B3, C4, D4, E4, G4}

2 / 20

slide-8
SLIDE 8

...in POPL’94, richer effect systems for concurrency

3 / 20

slide-9
SLIDE 9

...in POPL’94, richer effect systems for concurrency

4 / 20

slide-10
SLIDE 10

...in POPL’94, richer effect systems for concurrency

◮ Causality of operations (from sets to lists of effects)

4 / 20

slide-11
SLIDE 11

...in POPL’94, richer effect systems for concurrency

◮ Causality of operations (from sets to lists of effects)

(seq) Γ ⊢ e1 : τ1, Φ1

Γ ⊢ e2 : τ2, Φ2 Γ ⊢ e1; e2 : τ2, Φ1; Φ2

4 / 20

slide-12
SLIDE 12

...in POPL’94, richer effect systems for concurrency

◮ Causality of operations (from sets to lists of effects)

(seq) Γ ⊢ e1 : τ1, Φ1

Γ ⊢ e2 : τ2, Φ2 Γ ⊢ e1; e2 : τ2, Φ1; Φ2

◮ Branching control-flow (from lists to trees)

4 / 20

slide-13
SLIDE 13

...in POPL’94, richer effect systems for concurrency

◮ Causality of operations (from sets to lists of effects)

(seq) Γ ⊢ e1 : τ1, Φ1

Γ ⊢ e2 : τ2, Φ2 Γ ⊢ e1; e2 : τ2, Φ1; Φ2

◮ Branching control-flow (from lists to trees)

(if) Γ ⊢ e0 : bool, Φ0

Γ ⊢ e1 : τ, Φ1 Γ ⊢ e2 : τ, Φ2 Γ ⊢ if e0 then e1 else e2 : τ, Φ0; (Φ1 + Φ2)

4 / 20

slide-14
SLIDE 14

...in POPL’94, richer effect systems for concurrency

◮ Causality of operations (from sets to lists of effects)

(seq) Γ ⊢ e1 : τ1, Φ1

Γ ⊢ e2 : τ2, Φ2 Γ ⊢ e1; e2 : τ2, Φ1; Φ2

◮ Branching control-flow (from lists to trees)

(if) Γ ⊢ e0 : bool, Φ0

Γ ⊢ e1 : τ, Φ1 Γ ⊢ e2 : τ, Φ2 Γ ⊢ if e0 then e1 else e2 : τ, Φ0; (Φ1 + Φ2)

◮ Parallel control-flow

4 / 20

slide-15
SLIDE 15

...in POPL’94, richer effect systems for concurrency

◮ Causality of operations (from sets to lists of effects)

(seq) Γ ⊢ e1 : τ1, Φ1

Γ ⊢ e2 : τ2, Φ2 Γ ⊢ e1; e2 : τ2, Φ1; Φ2

◮ Branching control-flow (from lists to trees)

(if) Γ ⊢ e0 : bool, Φ0

Γ ⊢ e1 : τ, Φ1 Γ ⊢ e2 : τ, Φ2 Γ ⊢ if e0 then e1 else e2 : τ, Φ0; (Φ1 + Φ2)

◮ Parallel control-flow

(fork)

Γ ⊢ e : unit

Φ0

− → τ, ǫ Γ ⊢ fork e : τ, FORK Φ0

4 / 20

slide-16
SLIDE 16

...in 1999, rich general effect-system structure

5 / 20

slide-17
SLIDE 17

...in 1999, rich general effect-system structure

6 / 20

slide-18
SLIDE 18

...in 1999, rich general effect-system structure

7 / 20

slide-19
SLIDE 19

...in 1999, rich general effect-system structure

(Ordered) Semiring of effects (F, •, 1, +, ⊑)

7 / 20

slide-20
SLIDE 20

...in 1999, rich general effect-system structure

(Ordered) Semiring of effects (F, •, 1, +, ⊑)

◮ (F, •, 1) for sequential composition (monoid)

7 / 20

slide-21
SLIDE 21

...in 1999, rich general effect-system structure

(Ordered) Semiring of effects (F, •, 1, +, ⊑)

◮ (F, •, 1) for sequential composition (monoid) ◮ (F, +) for alternation (semigroup)

7 / 20

slide-22
SLIDE 22

...in 1999, rich general effect-system structure

(Ordered) Semiring of effects (F, •, 1, +, ⊑)

◮ (F, •, 1) for sequential composition (monoid) ◮ (F, +) for alternation (semigroup) ◮ ⊑ for subeffecting

7 / 20

slide-23
SLIDE 23

...in 1999, rich general effect-system structure

(Ordered) Semiring of effects (F, •, 1, +, ⊑)

◮ (F, •, 1) for sequential composition (monoid) ◮ (F, +) for alternation (semigroup) ◮ ⊑ for subeffecting ◮ ... with fixed-point recβ.Φ

7 / 20

slide-24
SLIDE 24

...in 1999, rich general effect-system structure

(Ordered) Semiring of effects (F, •, 1, +, ⊑)

◮ (F, •, 1) for sequential composition (monoid) ◮ (F, +) for alternation (semigroup) ◮ ⊑ for subeffecting ◮ ... with fixed-point recβ.Φ ◮ ... subeffecting axioms provide semiring equations, e.g.

(Φ1 + Φ2); Φ3 ⊑ (Φ1; Φ3) + (Φ1; Φ2) (Φ1; Φ3) + (Φ1; Φ2) ⊑ (Φ1 + Φ2); Φ3

7 / 20

slide-25
SLIDE 25

For our musical example...

Two example instances:

8 / 20

slide-26
SLIDE 26

For our musical example...

Two example instances:

◮ Song structure via term-algebra:

Φ = C, D, E, . . . , rest | Φ1 + Φ2 | Φ1 • Φ2 | Φ∗

8 / 20

slide-27
SLIDE 27

For our musical example...

Two example instances:

◮ Song structure via term-algebra:

Φ = C, D, E, . . . , rest | Φ1 + Φ2 | Φ1 • Φ2 | Φ∗ with Γ ⊢ play(N, L) : void, N

8 / 20

slide-28
SLIDE 28

For our musical example...

Two example instances:

◮ Song structure via term-algebra:

Φ = C, D, E, . . . , rest | Φ1 + Φ2 | Φ1 • Φ2 | Φ∗ with Γ ⊢ play(N, L) : void, N gives (G3•G3•(G4•E4•C4•B3•A3+A3•G3•(D4•C4+C4•B3)))∗

8 / 20

slide-29
SLIDE 29

For our musical example...

Two example instances:

◮ Song structure via term-algebra:

Φ = C, D, E, . . . , rest | Φ1 + Φ2 | Φ1 • Φ2 | Φ∗ with Γ ⊢ play(N, L) : void, N gives (G3•G3•(G4•E4•C4•B3•A3+A3•G3•(D4•C4+C4•B3)))∗

◮ or, timing via (R+, +, 0, max, ≤)

8 / 20

slide-30
SLIDE 30

For our musical example...

Two example instances:

◮ Song structure via term-algebra:

Φ = C, D, E, . . . , rest | Φ1 + Φ2 | Φ1 • Φ2 | Φ∗ with Γ ⊢ play(N, L) : void, N gives (G3•G3•(G4•E4•C4•B3•A3+A3•G3•(D4•C4+C4•B3)))∗

◮ or, timing via (R+, +, 0, max, ≤)

with Γ ⊢ play(N, L) : void, L

8 / 20

slide-31
SLIDE 31

For our musical example...

Two example instances:

◮ Song structure via term-algebra:

Φ = C, D, E, . . . , rest | Φ1 + Φ2 | Φ1 • Φ2 | Φ∗ with Γ ⊢ play(N, L) : void, N gives (G3•G3•(G4•E4•C4•B3•A3+A3•G3•(D4•C4+C4•B3)))∗

◮ or, timing via (R+, +, 0, max, ≤)

with Γ ⊢ play(N, L) : void, L gives 13 seconds

8 / 20

slide-32
SLIDE 32

from “Type and effect systems” (Nielson, Nielson, 1999)

“Now we turn to explaining the individual steps in the overall methodology of designing and using type and effect systems: – devise a semantics for the programming language, – develop a program analysis in the form of a type and effect system ... – prove the semantic correctness of the analysis, – develop an efficient inference algorithm, ...”

9 / 20

slide-33
SLIDE 33

from “Type and effect systems” (Nielson, Nielson, 1999)

“Now we turn to explaining the individual steps in the overall methodology of designing and using type and effect systems: – devise a semantics for the programming language, – develop a program analysis in the form of a type and effect system ... – prove the semantic correctness of the analysis, – develop an efficient inference algorithm, ...”

9 / 20

slide-34
SLIDE 34

from “Type and effect systems” (Nielson, Nielson, 1999)

“Now we turn to explaining the individual steps in the overall methodology of designing and using type and effect systems: – devise a semantics for the programming language, – develop a program analysis in the form of a type and effect system ... – prove the semantic correctness of the analysis, – develop an efficient inference algorithm, ...”

9 / 20

slide-35
SLIDE 35

from “Type and effect systems” (Nielson, Nielson, 1999)

“Now we turn to explaining the individual steps in the overall methodology of designing and using type and effect systems: – devise a semantics for the programming language, – develop a program analysis in the form of a type and effect system ... – prove the semantic correctness of the analysis, – develop an efficient inference algorithm, ...”

9 / 20

slide-36
SLIDE 36

from “Type and effect systems” (Nielson, Nielson, 1999)

“Now we turn to explaining the individual steps in the overall methodology of designing and using type and effect systems: – devise a semantics for the programming language, – develop a program analysis in the form of a type and effect system ... – prove the semantic correctness of the analysis, – develop an efficient inference algorithm, ...”

◮ An effect-directed semantics unifies the first three steps

9 / 20

slide-37
SLIDE 37

from “Type and effect systems” (Nielson, Nielson, 1999)

“Now we turn to explaining the individual steps in the overall methodology of designing and using type and effect systems: – devise a semantics for the programming language, – develop a program analysis in the form of a type and effect system ... – prove the semantic correctness of the analysis, – develop an efficient inference algorithm, ...”

◮ An effect-directed semantics unifies the first three steps ◮ We develop an effect-directed semantics for rich

Nielson-Nielson-style effects

9 / 20

slide-38
SLIDE 38

Type-directed semantics

10 / 20

slide-39
SLIDE 39

Type-directed semantics

untyped model: e : D D ∼ = Z + (D → D) + {wrong}

10 / 20

slide-40
SLIDE 40

Type-directed semantics

untyped model: e : D D ∼ = Z + (D → D) + {wrong} simply typed model: Γ ⊢ e : τ : Dτ Dint = Z Dσ→τ = Dσ → Dτ

10 / 20

slide-41
SLIDE 41

Type-directed semantics

untyped model: e : D D ∼ = Z + (D → D) + {wrong} simply typed model: Γ ⊢ e : τ : Dτ Dint = Z Dσ→τ = Dσ → Dτ effect-directed model: Γ ⊢ e : τ, F : DF

τ

10 / 20

slide-42
SLIDE 42

Type-directed semantics

untyped model: e : D D ∼ = Z + (D → D) + {wrong} simply typed model: Γ ⊢ e : τ : Dτ Dint = Z Dσ→τ = Dσ → Dτ effect-directed model: Γ ⊢ e : τ, F : DF

τ

Core idea: algebra-semantics homomorphism Algebraic structure of F determines structure on family DF

τ .

10 / 20

slide-43
SLIDE 43

Effect analysis and semantics

Lattice effects (Gifford, Lucassen ’86) Γ ⊢ e : τ, F

  • Richer structure on F

(Nielson, Nielson ’94, ’99)

  • “Marriage of effects and monads”

(Wadler, Thiemann ’03) Γ ⊢ e : MFτ : Γ → Tτ

  • Effect-directed semantics

(Katsumata ’14) Γ ⊢ e : MFτ : Γ → TFτ (graded monads)

  • This paper

Richer effect-directed semantics (graded joinads)

11 / 20

slide-44
SLIDE 44

Effect analysis and semantics

Lattice effects (Gifford, Lucassen ’86) Γ ⊢ e : τ, F

  • Richer structure on F

(Nielson, Nielson ’94, ’99)

  • “Marriage of effects and monads”

(Wadler, Thiemann ’03) Γ ⊢ e : MFτ : Γ → Tτ

  • Effect-directed semantics

(Katsumata ’14) Γ ⊢ e : MFτ : Γ → TFτ (graded monads)

  • This paper

Richer effect-directed semantics (graded joinads) Operations on TF homomorphic to operations on F

11 / 20

slide-45
SLIDE 45

Modelling effects with graded monads (Katsumata 2014)

12 / 20

slide-46
SLIDE 46

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ

12 / 20

slide-47
SLIDE 47

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TA = S → (A × S).

12 / 20

slide-48
SLIDE 48

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TFA = (reads(F)) → (A × writes(F)).

12 / 20

slide-49
SLIDE 49

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TFA = (reads(F)) → (A × writes(F)). e.g. for partiality TA = ⊥ + A

12 / 20

slide-50
SLIDE 50

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TFA = (reads(F)) → (A × writes(F)). e.g. for partiality T⊥A = ⊥, T⊤A = A,

12 / 20

slide-51
SLIDE 51

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TFA = (reads(F)) → (A × writes(F)). e.g. for partiality T⊥A = ⊥, T⊤A = A, T?A = A + 1

slide-52
SLIDE 52

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TFA = (reads(F)) → (A × writes(F)). e.g. for partiality T⊥A = ⊥, T⊤A = A, T?A = A + 1 Graded monads provide sequential composition

slide-53
SLIDE 53

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TFA = (reads(F)) → (A × writes(F)). e.g. for partiality T⊥A = ⊥, T⊤A = A, T?A = A + 1 Graded monads provide sequential composition Let (F, •, 0) be an effect monoid.

slide-54
SLIDE 54

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TFA = (reads(F)) → (A × writes(F)). e.g. for partiality T⊥A = ⊥, T⊤A = A, T?A = A + 1 Graded monads provide sequential composition Let (F, •, 0) be an effect monoid. Given d1 : A → TFB and d2 : B → TGC

slide-55
SLIDE 55

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TFA = (reads(F)) → (A × writes(F)). e.g. for partiality T⊥A = ⊥, T⊤A = A, T?A = A + 1 Graded monads provide sequential composition Let (F, •, 0) be an effect monoid. Given d1 : A → TFB and d2 : B → TGC then d2 ˆ

  • d1 : A → TF•GC
slide-56
SLIDE 56

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TFA = (reads(F)) → (A × writes(F)). e.g. for partiality T⊥A = ⊥, T⊤A = A, T?A = A + 1 Graded monads provide sequential composition Let (F, •, 0) be an effect monoid. Given d1 : A → TFB and d2 : B → TGC then d2 ˆ

  • d1 : A → TF•GC with ˆ

idA : A → T0A.

12 / 20

slide-57
SLIDE 57

Modelling effects with graded monads (Katsumata 2014)

Γ ⊢ e : τ, F : Γ → TFτ e.g. for state TFA = (reads(F)) → (A × writes(F)). e.g. for partiality T⊥A = ⊥, T⊤A = A, T?A = A + 1 Graded monads provide sequential composition Let (F, •, 0) be an effect monoid. Given d1 : A → TFB and d2 : B → TGC then d2 ˆ

  • d1 : A → TF•GC with ˆ

idA : A → T0A. With ordering Given partially ordered (F, •, 0, ⊑) then for all F ⊑ G then coercion: ιF,G,A : TFA → TGA

12 / 20

slide-58
SLIDE 58

Semantics of branching: derived vs. parameterised

13 / 20

slide-59
SLIDE 59

Semantics of branching: derived vs. parameterised

if e0 then e1 else e2 = COND(e0, e1, e2)

13 / 20

slide-60
SLIDE 60

Semantics of branching: derived vs. parameterised

if e0 then e1 else e2 = COND(e0, e1, e2)

◮ COND definable via cond : B × A × A → A

13 / 20

slide-61
SLIDE 61

Semantics of branching: derived vs. parameterised

if e0 then e1 else e2 = COND(e0, e1, e2)

◮ COND definable via cond : B × A × A → A

cond(true, x, y) = x cond(false, x, y) = y

13 / 20

slide-62
SLIDE 62

Semantics of branching: derived vs. parameterised

if e0 then e1 else e2 = COND(e0, e1, e2)

◮ COND definable via cond : B × A × A → A

cond(true, x, y) = x cond(false, x, y) = y

◮ Restricts effect branching behaviour:

13 / 20

slide-63
SLIDE 63

Semantics of branching: derived vs. parameterised

if e0 then e1 else e2 = COND(e0, e1, e2)

◮ COND definable via cond : B × A × A → A

cond(true, x, y) = x cond(false, x, y) = y

◮ Restricts effect branching behaviour:

(if) Γ ⊢ e0 : bool, F

Γ ⊢ e1 : τ, G Γ ⊢ e2 : τ, H Γ ⊢ if e0 then e1 else e2 : τ, F • (G ⊔ H)

13 / 20

slide-64
SLIDE 64

Semantics of branching: derived vs. parameterised

if e0 then e1 else e2 = COND(e0, e1, e2)

◮ COND definable via cond : B × A × A → A

cond(true, x, y) = x cond(false, x, y) = y

◮ Restricts effect branching behaviour:

(if) Γ ⊢ e0 : bool, F

Γ ⊢ e1 : τ, G Γ ⊢ e2 : τ, H Γ ⊢ if e0 then e1 else e2 : τ, F • (G ⊔ H) cond : B × TG⊔HA × TG⊔HA → TG⊔HA

13 / 20

slide-65
SLIDE 65

Semantics of branching: derived vs. parameterised

if e0 then e1 else e2 = COND(e0, e1, e2)

◮ COND definable via cond : B × A × A → A

cond(true, x, y) = x cond(false, x, y) = y

◮ Restricts effect branching behaviour:

(if) Γ ⊢ e0 : bool, F

Γ ⊢ e1 : τ, G Γ ⊢ e2 : τ, H Γ ⊢ if e0 then e1 else e2 : τ, F • (G ⊔ H) cond : B × TG⊔HA × TG⊔HA → TG⊔HA

◮ Towards Nielson-Nielson richer effects, but + may not be ⊔.

13 / 20

slide-66
SLIDE 66

Semantics of branching: derived vs. parameterised

if e0 then e1 else e2 = COND(e0, e1, e2)

◮ COND definable via cond : B × A × A → A

cond(true, x, y) = x cond(false, x, y) = y

◮ Restricts effect branching behaviour:

(if) Γ ⊢ e0 : bool, F

Γ ⊢ e1 : τ, G Γ ⊢ e2 : τ, H Γ ⊢ if e0 then e1 else e2 : τ, F • (G ⊔ H) cond : B × TG⊔HA × TG⊔HA → TG⊔HA

◮ Towards Nielson-Nielson richer effects, but + may not be ⊔. ◮ Instead: parameterise semantics on

COND : TFB × TGA × THA → T?

+(F,G,H)A

13 / 20

slide-67
SLIDE 67

Definition: jonoid For a set of effects F then (F, •, I, &, ? +, ⊑) is a joinoid control-flow algebra:

slide-68
SLIDE 68

Definition: jonoid For a set of effects F then (F, •, I, &, ? +, ⊑) is a joinoid control-flow algebra:

◮ (F, •, I) is a monoid, representing sequential

composition and purity;

slide-69
SLIDE 69

Definition: jonoid For a set of effects F then (F, •, I, &, ? +, ⊑) is a joinoid control-flow algebra:

◮ (F, •, I) is a monoid, representing sequential

composition and purity;

◮ (F, &, I) is a commutative monoid, representing

parallel composition;

slide-70
SLIDE 70

Definition: jonoid For a set of effects F then (F, •, I, &, ? +, ⊑) is a joinoid control-flow algebra:

◮ (F, •, I) is a monoid, representing sequential

composition and purity;

◮ (F, &, I) is a commutative monoid, representing

parallel composition;

◮ letting F + G = ?

+(I, F, G) (pure guard)

slide-71
SLIDE 71

Definition: jonoid For a set of effects F then (F, •, I, &, ? +, ⊑) is a joinoid control-flow algebra:

◮ (F, •, I) is a monoid, representing sequential

composition and purity;

◮ (F, &, I) is a commutative monoid, representing

parallel composition;

◮ letting F + G = ?

+(I, F, G) (pure guard) (F, +) is a semigroup, representing choice between branches

slide-72
SLIDE 72

Definition: jonoid For a set of effects F then (F, •, I, &, ? +, ⊑) is a joinoid control-flow algebra:

◮ (F, •, I) is a monoid, representing sequential

composition and purity;

◮ (F, &, I) is a commutative monoid, representing

parallel composition;

◮ letting F + G = ?

+(I, F, G) (pure guard) (F, +) is a semigroup, representing choice between branches

◮ with right-distributivity axioms:

slide-73
SLIDE 73

Definition: jonoid For a set of effects F then (F, •, I, &, ? +, ⊑) is a joinoid control-flow algebra:

◮ (F, •, I) is a monoid, representing sequential

composition and purity;

◮ (F, &, I) is a commutative monoid, representing

parallel composition;

◮ letting F + G = ?

+(I, F, G) (pure guard) (F, +) is a semigroup, representing choice between branches

◮ with right-distributivity axioms:

(F + G) • H = (F • H) + (G • H) (F + G) & H = (F & H) + (G & H)

slide-74
SLIDE 74

Definition: jonoid For a set of effects F then (F, •, I, &, ? +, ⊑) is a joinoid control-flow algebra:

◮ (F, •, I) is a monoid, representing sequential

composition and purity;

◮ (F, &, I) is a commutative monoid, representing

parallel composition;

◮ letting F + G = ?

+(I, F, G) (pure guard) (F, +) is a semigroup, representing choice between branches

◮ with right-distributivity axioms:

(F + G) • H = (F • H) + (G • H) (F + G) & H = (F & H) + (G & H)

◮ all operations are monotonic with respect to ⊑.

14 / 20

slide-75
SLIDE 75

Graded generalised joinad

Definition: graded conditional joinad Given a jonoid (F, •, I, &, ? +, ⊑):

slide-76
SLIDE 76

Graded generalised joinad

Definition: graded conditional joinad Given a jonoid (F, •, I, &, ? +, ⊑):

◮ graded monad for the pre-ordered monoid (F, •, I, ⊑)

slide-77
SLIDE 77

Graded generalised joinad

Definition: graded conditional joinad Given a jonoid (F, •, I, &, ? +, ⊑):

◮ graded monad for the pre-ordered monoid (F, •, I, ⊑) ◮ additional operations:

slide-78
SLIDE 78

Graded generalised joinad

Definition: graded conditional joinad Given a jonoid (F, •, I, &, ? +, ⊑):

◮ graded monad for the pre-ordered monoid (F, •, I, ⊑) ◮ additional operations:

condF,G,H,A :TFB × TGA × THA → T?

+(F,G,H)A

parF,G,A :TFA × TGA → TF&GA

slide-79
SLIDE 79

Graded generalised joinad

Definition: graded conditional joinad Given a jonoid (F, •, I, &, ? +, ⊑):

◮ graded monad for the pre-ordered monoid (F, •, I, ⊑) ◮ additional operations:

condF,G,H,A :TFB × TGA × THA → T?

+(F,G,H)A

parF,G,A :TFA × TGA → TF&GA

◮ Satisfy jonoid axioms (modulo lifting to functors)

15 / 20

slide-80
SLIDE 80

Graded generalised joinad

Definition: graded conditional joinad Given a jonoid (F, •, I, &, ? +, ⊑):

◮ graded monad for the pre-ordered monoid (F, •, I, ⊑) ◮ additional operations:

condF,G,H,A :TFB × TGA × THA → T?

+(F,G,H)A

parF,G,A :TFA × TGA → TF&GA

◮ Satisfy jonoid axioms (modulo lifting to functors)

where ? + = cond and & = par Monoids are to (graded) monads as jonoids are to (graded) joinads

15 / 20

slide-81
SLIDE 81

Theorem: soundness Given a graded joinadic semantics for the simply-effect-and- typed λ-calculus with if and par then, for all e, e′, Γ, τ, F:

slide-82
SLIDE 82

Theorem: soundness Given a graded joinadic semantics for the simply-effect-and- typed λ-calculus with if and par then, for all e, e′, Γ, τ, F: Γ ⊢ e ≡ e′ : τ, F ⇒ Γ ⊢ e : τ, F = Γ ⊢ e′ : τ, F

slide-83
SLIDE 83

Theorem: soundness Given a graded joinadic semantics for the simply-effect-and- typed λ-calculus with if and par then, for all e, e′, Γ, τ, F: Γ ⊢ e ≡ e′ : τ, F ⇒ Γ ⊢ e : τ, F = Γ ⊢ e′ : τ, F

  • wrt. CBV β-≡ with additional equations:
slide-84
SLIDE 84

Theorem: soundness Given a graded joinadic semantics for the simply-effect-and- typed λ-calculus with if and par then, for all e, e′, Γ, τ, F: Γ ⊢ e ≡ e′ : τ, F ⇒ Γ ⊢ e : τ, F = Γ ⊢ e′ : τ, F

  • wrt. CBV β-≡ with additional equations:

(ifβ1’)

if true then e else x ≡ e

(ifβ2’)

if false then x else e′ ≡ e′

(if-dist-par)

(if b then e else e′) par e′′ ≡ if b then (e par e′′) else (e′ par e′′)

(if-dist-seq)

let x = (if e then e′ else e′′) in e′′′ ≡ if e then (let x = e′ in e′′′) else (let x = e′′ in e′′′)

(par-pure)

x par e ≡ (x, e)

(par-sym)

e par e′ ≡ swap (e′ par e)

(par-assoc)

e par (e′ par e′′) ≡ assoc ((e par e′) par e′′)

16 / 20

slide-85
SLIDE 85

Conclusions

17 / 20

slide-86
SLIDE 86

Conclusions

◮ unify Hanne and Flemming’s rich effects with semantics

17 / 20

slide-87
SLIDE 87

Conclusions

◮ unify Hanne and Flemming’s rich effects with semantics

monads

indexing

− − − − − → graded monads

non-seq. control

− − − − − − − − − → graded joinads

17 / 20

slide-88
SLIDE 88

Conclusions

◮ unify Hanne and Flemming’s rich effects with semantics

monads

indexing

− − − − − → graded monads

non-seq. control

− − − − − − − − − → graded joinads

◮ Semantics for various kinds of parallel, concurrent (e.g. music)

and speculative behaviour (e.g. prefetching)

17 / 20

slide-89
SLIDE 89

Conclusions

◮ unify Hanne and Flemming’s rich effects with semantics

monads

indexing

− − − − − → graded monads

non-seq. control

− − − − − − − − − → graded joinads

◮ Semantics for various kinds of parallel, concurrent (e.g. music)

and speculative behaviour (e.g. prefetching)

◮ Considerable simplification to proofs

17 / 20

slide-90
SLIDE 90

Conclusions

◮ unify Hanne and Flemming’s rich effects with semantics

monads

indexing

− − − − − → graded monads

non-seq. control

− − − − − − − − − → graded joinads

◮ Semantics for various kinds of parallel, concurrent (e.g. music)

and speculative behaviour (e.g. prefetching)

◮ Considerable simplification to proofs ◮ Represent effect-dependent optimisations more easily

17 / 20

slide-91
SLIDE 91

Conclusions

◮ unify Hanne and Flemming’s rich effects with semantics

monads

indexing

− − − − − → graded monads

non-seq. control

− − − − − − − − − → graded joinads

◮ Semantics for various kinds of parallel, concurrent (e.g. music)

and speculative behaviour (e.g. prefetching)

◮ Considerable simplification to proofs ◮ Represent effect-dependent optimisations more easily ◮ Effect-directed semantics provides co-design approach

17 / 20

slide-92
SLIDE 92

Conclusions

◮ unify Hanne and Flemming’s rich effects with semantics

monads

indexing

− − − − − → graded monads

non-seq. control

− − − − − − − − − → graded joinads

◮ Semantics for various kinds of parallel, concurrent (e.g. music)

and speculative behaviour (e.g. prefetching)

◮ Considerable simplification to proofs ◮ Represent effect-dependent optimisations more easily ◮ Effect-directed semantics provides co-design approach

◮ Equations of analysis carry over to semantics, and vice versa 17 / 20

slide-93
SLIDE 93

Conclusions

◮ unify Hanne and Flemming’s rich effects with semantics

monads

indexing

− − − − − → graded monads

non-seq. control

− − − − − − − − − → graded joinads

◮ Semantics for various kinds of parallel, concurrent (e.g. music)

and speculative behaviour (e.g. prefetching)

◮ Considerable simplification to proofs ◮ Represent effect-dependent optimisations more easily ◮ Effect-directed semantics provides co-design approach

◮ Equations of analysis carry over to semantics, and vice versa ◮ Exposes which structure is needed in each direction 17 / 20

slide-94
SLIDE 94

Thanks Hanne and Flemming for the inspiration. Happy Birthday!

Thanks to Sam Aaron (Cambridge) for the Sonic Pi language used for the intro program

18 / 20

slide-95
SLIDE 95

Backup slides

19 / 20

slide-96
SLIDE 96

Modeling effects with monads

Model effectful computations via some data type T

20 / 20

slide-97
SLIDE 97

Modeling effects with monads

Model effectful computations via some data type T Γ ⊢ e : τ : Γ → Tτ

20 / 20

slide-98
SLIDE 98

Modeling effects with monads

Model effectful computations via some data type T Γ ⊢ e : τ : Γ → Tτ e.g. for state TA = S → (A × S).

20 / 20

slide-99
SLIDE 99

Modeling effects with monads

Model effectful computations via some data type T Γ ⊢ e : τ : Γ → Tτ e.g. for state TA = S → (A × S). e.g. for partiality TA = ⊥ + A

20 / 20

slide-100
SLIDE 100

Modeling effects with monads

Model effectful computations via some data type T Γ ⊢ e : τ : Γ → Tτ e.g. for state TA = S → (A × S). e.g. for partiality TA = ⊥ + A Monads provide sequential composition Given f : A → TB and g : B → TC then

slide-101
SLIDE 101

Modeling effects with monads

Model effectful computations via some data type T Γ ⊢ e : τ : Γ → Tτ e.g. for state TA = S → (A × S). e.g. for partiality TA = ⊥ + A Monads provide sequential composition Given f : A → TB and g : B → TC then g ˆ

  • f : A → TC
slide-102
SLIDE 102

Modeling effects with monads

Model effectful computations via some data type T Γ ⊢ e : τ : Γ → Tτ e.g. for state TA = S → (A × S). e.g. for partiality TA = ⊥ + A Monads provide sequential composition Given f : A → TB and g : B → TC then g ˆ

  • f : A → TC

with ˆ idA : A → TA.

20 / 20