Mixin Modules and Computational Effects Davide Ancona and Sonia - - PowerPoint PPT Presentation

mixin modules and computational effects
SMART_READER_LITE
LIVE PREVIEW

Mixin Modules and Computational Effects Davide Ancona and Sonia - - PowerPoint PPT Presentation

Mixin Modules and Computational Effects Davide Ancona and Sonia Fagorzi and Eugenio Moggi and Elena Zucca {davide, fagorzi, moggi, zucca}@disi.unige.it Dipartimento di Informatica e Scienze dellInformazione (DISI) University of Genova To


slide-1
SLIDE 1

Mixin Modules and Computational Effects

Davide Ancona and Sonia Fagorzi and Eugenio Moggi and Elena Zucca

{davide, fagorzi, moggi, zucca}@disi.unige.it

Dipartimento di Informatica e Scienze dell’Informazione (DISI) University of Genova To appear in ICALP 2003

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.1/28

slide-2
SLIDE 2

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.2/28

slide-3
SLIDE 3

Aim

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.3/28

slide-4
SLIDE 4

Aim

To study the interaction between the notions of mixin (modules) and computational effects

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.3/28

slide-5
SLIDE 5

Aim

To study the interaction between the notions of mixin (modules) and computational effects All formalizations of mixin systems defined so far ([Bra92], [DS96@ICFP], [AZ99@PPDP] [AZ02@JFP] [MT00@ESOP] [WV00@ESOP]) only model mixins in purely functional settings

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.3/28

slide-6
SLIDE 6

Aim

To study the interaction between the notions of mixin (modules) and computational effects All formalizations of mixin systems defined so far ([Bra92], [DS96@ICFP], [AZ99@PPDP] [AZ02@JFP] [MT00@ESOP] [WV00@ESOP]) only model mixins in purely functional settings Our proposal is a (foundational) monadic mixin calculus, called CMS do,

  • btained by combining:

the purely functional mixin calculus CMS [AZ99@PPDP ,AZ02@JFP] a monadic metalanguage [MF03@FOSSACS] equipped with a Haskell-like recursive monadic binding [EL00@ICFP ,EL02@HASKELL]

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.3/28

slide-7
SLIDE 7

Aim

To study the interaction between the notions of mixin (modules) and computational effects All formalizations of mixin systems defined so far ([Bra92], [DS96@ICFP], [AZ99@PPDP] [AZ02@JFP] [MT00@ESOP] [WV00@ESOP]) only model mixins in purely functional settings Our proposal is a (foundational) monadic mixin calculus, called CMS do,

  • btained by combining:

the purely functional mixin calculus CMS [AZ99@PPDP ,AZ02@JFP] a monadic metalanguage [MF03@FOSSACS] equipped with a Haskell-like recursive monadic binding [EL00@ICFP ,EL02@HASKELL] The semantics of the monadic language consists of two parts: local (semantics preserving) simplification rules computation steps able to modify the store This has simplified the integration since CMS rules are all local

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.3/28

slide-8
SLIDE 8

Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.4/28

slide-9
SLIDE 9

Summary

An informal overview of the CMS calculus

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.4/28

slide-10
SLIDE 10

Summary

An informal overview of the CMS calculus Mixin modules and imperative features: semantic issues

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.4/28

slide-11
SLIDE 11

Summary

An informal overview of the CMS calculus Mixin modules and imperative features: semantic issues CMS do: an informal overview of the novelties with respect to CMS Example 1: basic modules and doall operation Examples 2 and 3: mutual recursion

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.4/28

slide-12
SLIDE 12

Summary

An informal overview of the CMS calculus Mixin modules and imperative features: semantic issues CMS do: an informal overview of the novelties with respect to CMS Example 1: basic modules and doall operation Examples 2 and 3: mutual recursion Future work and conclusion

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.4/28

slide-13
SLIDE 13

An informal overview of the CMS calculus

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.5/28

slide-14
SLIDE 14

An informal overview of the CMS calculus

A CMS basic mixin module Example M1 = mix import N2 as x (* deferred *) export N1 = e1[x,y] (* defined *) local y = e2[x,y] (* local *) end It consists of defined and local components, bound to an expression, and deferred components, declared but not yet defined Separation between component names and variables

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.5/28

slide-15
SLIDE 15

An informal overview of the CMS calculus

A CMS basic mixin module Example M1 = mix import N2 as x (* deferred *) export N1 = e1[x,y] (* defined *) local y = e2[x,y] (* local *) end It consists of defined and local components, bound to an expression, and deferred components, declared but not yet defined Separation between component names and variables

CMS provides three operations on mixins: sum, freeze and delete Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.5/28

slide-16
SLIDE 16

Operations: sum

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.6/28

slide-17
SLIDE 17

Operations: sum

The sum operator: performs the union of the deferred components, and the disjoint union of the defined and local components of the two mixins Example: M1 = mix import N2 as x export N1 = e1[x,y] local y = e2[x,y] end M2 = mix import N1 as x export N2 = e3[x,y] local y = e4[x,y] end M3 = M1 + M2

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.6/28

slide-18
SLIDE 18

Operations: sum

The sum operator: performs the union of the deferred components, and the disjoint union of the defined and local components of the two mixins Example: M1 = mix import N2 as x export N1 = e1[x,y] local y = e2[x,y] end M2 = mix import N1 as x export N2 = e3[x,y] local y = e4[x,y] end M3 = M1 + M2 simplifies to mix import N2 as x1, N1 as x2 export N1 = e1[x1,y1] local y1 = e2[x1,y1] export N2 = e3[x2,y2] local y2 = e4[x2,y2] end The sum operation supports mutual dependecies and cross-module recursion

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.6/28

slide-19
SLIDE 19

Operations: freeze and delete

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.7/28

slide-20
SLIDE 20

Operations: freeze and delete

The freeze operator: connects deferred and defined components having the same name inside a mixin Example: (mix import N as x export N = e1[x,y] local y = e2[x,y] end) ! N simplifies to mix local x = e1[x,y] export N = x local y = e2[x,y] end

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.7/28

slide-21
SLIDE 21

Operations: freeze and delete

The freeze operator: connects deferred and defined components having the same name inside a mixin Example: (mix import N as x export N = e1[x,y] local y = e2[x,y] end) ! N simplifies to mix local x = e1[x,y] export N = x local y = e2[x,y] end The delete operator: is used for hiding defined components Example: (mix import N as x export N = e1[x,y] local y = e2[x,y] end) \ N simplifies to mix import N as x local y = e2[x,y] end

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.7/28

slide-22
SLIDE 22

Mixin modules and imperative features: semantic issues

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.8/28

slide-23
SLIDE 23

Mixin modules and imperative features: semantic issues

In the presence of primitives for store manipulation, expressions inside mixins can have side-effects. This raises the following issues: because of side-effects, the evaluation order of components inside a mixin must be deterministic, while still retaining cross-module-recursion when computations inside a mixin must be evaluated and how many times?

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.8/28

slide-24
SLIDE 24

Example 1: basic modules and doall operation

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.9/28

slide-25
SLIDE 25

Example 1: basic modules and doall operation

CM1 = mix local l ⇐ new(x-1), (* computational *) x = 1 export Inc = mdo v ⇐ get(l) in set(l,v+1), Val ⇐ get(l) (* computational *) end

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.9/28

slide-26
SLIDE 26

Example 1: basic modules and doall operation

CM1 = mix local l ⇐ new(x-1), (* computational *) x = 1 export Inc = mdo v ⇐ get(l) in set(l,v+1), Val ⇐ get(l) (* computational *) end Additions to CMS: τ ∈ T : : = . . . | Mτ | refτ | {Π} | [Π; Π′] primitives on the store the monadic constructs mdo (recursive do) and ret a new kind of mixin component called computational, of the form x⇐e (e with monadic type) doall: [∅; Π] → M{Π}

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.9/28

slide-27
SLIDE 27

Example 1: basic modules and doall operation

CM1 = mix local l ⇐ new(x-1), (* computational *) x = 1 export Inc = mdo v ⇐ get(l) in set(l,v+1), Val ⇐ get(l) (* computational *) end Additions to CMS: τ ∈ T : : = . . . | Mτ | refτ | {Π} | [Π; Π′] primitives on the store the monadic constructs mdo (recursive do) and ret a new kind of mixin component called computational, of the form x⇐e (e with monadic type) doall: [∅; Π] → M{Π} Mutual recursion has the following informal semantics: if i ≤ j, then ei can depend

  • n the variable xj, provided that the computation ei can be successfully performed

without knowing the value of ej

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.9/28

slide-28
SLIDE 28

Example 1: basic modules and doall operation

CM1 = mix local l ⇐ new(x-1), (* computational *) x = 1 export Inc = mdo v ⇐ get(l) in set(l,v+1), Val ⇐ get(l) (* computational *) end A new mixin operation doall to transform a mixin (without deferred components) into a record (selection is allowed only over record): it evaluates all computational definitions xi ⇐ ei in the order they are declared (oreder matters) it binds the value returned by ei to xi immediately, to make it available to the subsequent computations ej with j > i doall(CM1) evaluates to r

= {

Inc = mdo v ⇐ get(l) in set(l,v+1), Val = 0 } where l is the location generated by new(x-1)

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.9/28

slide-29
SLIDE 29

Example 1: basic modules and doall operation

CM1 = mix local l ⇐ new(x-1), (* computational *) x = 1 export Inc = mdo v ⇐ get(l) in set(l,v+1), Val ⇐ get(l) (* computational *) end r

= {

Inc = mdo v ⇐ get(l) in set(l,v+1), Val = 0 } Inc can be reevaluated several times: Example mdo l⇐r.Inc in get(l) evaluates to

1

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.9/28

slide-30
SLIDE 30

Examples 2 and 3: mutual recursion

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.10/28

slide-31
SLIDE 31

Examples 2 and 3: mutual recursion

Example 2: computational components can be mutually recursive doall (mix export Loc1=l1, Loc2=l2 local l1 ⇐ new(l2), l2 ⇐ new(l1) end evaluates to

{ Loc1 = l1, Loc2 = l2 }

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.10/28

slide-32
SLIDE 32

Examples 2 and 3: mutual recursion

Example 2: computational components can be mutually recursive doall (mix export Loc1=l1, Loc2=l2 local l1 ⇐ new(l2), l2 ⇐ new(l1) end evaluates to

{ Loc1 = l1, Loc2 = l2 }

Example 3: bad recursive declarations doall (mix local x ⇐ set(y, 1) local y ⇐ new(0) end) evaluates to error

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.10/28

slide-33
SLIDE 33

Conclusion and future work

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.11/28

slide-34
SLIDE 34

Conclusion and future work

Emphasis of the paper is on the operational aspects, we adopt a simple type system More refined type systems:

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.11/28

slide-35
SLIDE 35

Conclusion and future work

Emphasis of the paper is on the operational aspects, we adopt a simple type system More refined type systems: dynamic errors due to bad recursive declarations mentioned above could be detected by introducing a type system similar to that in [HL02@ESOP ,Bou02@JFP]

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.11/28

slide-36
SLIDE 36

Conclusion and future work

Emphasis of the paper is on the operational aspects, we adopt a simple type system More refined type systems: dynamic errors due to bad recursive declarations mentioned above could be detected by introducing a type system similar to that in [HL02@ESOP ,Bou02@JFP] a type system distinguishing between modules possibly containing some computational definitions and those with no computational definitions, would allow selection on CMS do mixins without any need to apply doall(_)

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.11/28

slide-37
SLIDE 37

References

[AZ99@PPDP]

  • D. Ancona and E. Zucca. A primitive calculus for module sys-
  • tems. In G. Nadathur, editor, Principles and Practice of Declara-

tive Programming, 1999, number 1702 in Lecture Notes in Com- puter Science, pages 62–79. Springer Verlag, 1999 [AZ02@JFP] D.Ancona and E.Zucca. A calculus of module systems. Journal

  • f Functional Programming, 12(2):91–132, March 2002

[Bou02@JFP]

  • G. Boudol.. The recursive record semantics of objects revisited.

To appear in Journal of Functional Programming, 2002 [Bra92]

  • G. Bracha. The programming language JIGSAW: Mixin, modular-

ity and multiple inheritance. PhD thesis, Department of Computer Science, University of Utah, 1992 [DS96@ICFP]

  • D. Duggan and C. Sourelis. Mixin modules. Intl Conf. on Func-

tional Programming, pp. 262-273, ACM Press, 1996 [EL00@ICFP]

  • L. Erkök and J. Launchbury. Recursive monadic bindings. In Intl.
  • Conf. on Functional Programming 2000, pages 174–185, 2000

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.12/28

slide-38
SLIDE 38

References (cont)

[EL02@HASKELL]

  • L. Erkök and J. Launchbury. A recursive do for Haskell. In

Haskell Workshop’02, pages 29–37, 2002 [HL02@ESOP]

  • T. Hirschowitz and X. Leroy. Mixin modules in a call-by-

value setting. In D. Le Métayer, editor, ESOP 2002 - Pro- gramming Languages and Systems, number 2305 in Lec- ture Notes in Computer Science, pages 6–20. Springer Verlag, 2002 [MF03@FOSSACS]

  • E. Moggi and S. Fagorzi. A monadic multi-stage metalan-
  • guage. In Proceedings Workshop on Foundations of Soft-

ware Science and Computation Structures, Warsaw 2003,

  • LNCS. Springer Verlag, 2003. To appear

[MT00@ESOP]

  • E. Machkasova and F

.A. Turbak. A calculus for link-time compilation. In G. Smolka, editor, ESOP 2000 - Pro- gramming Languages and Systems, number 1782 in Lec- ture Notes in Computer Science, pages 260–274, Berlin. Springer Verlag, 2000

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.13/28

slide-39
SLIDE 39

References (cont)

[WV00@ESOP] J.B. Wells and R. Vestergaard. Equational reasoning for linking with first-class primitive modules. In G. Smolka, editor, ESOP 2000 - Programming Languages and Sys- tems, number 1782 in Lecture Notes in Computer Science, pages 412–428, Berlin, 2000. Springer Verlag, 2000

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.14/28

slide-40
SLIDE 40

Summary of the technical contents

Syntax Type system Semantics Simplification Computation Technical results

Back to the First Part Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.15/28

slide-41
SLIDE 41

Syntax

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.16/28

slide-42
SLIDE 42

Syntax

Syntax e ∈ Exp: : = x | {o} | e.X | let(ρ; e) | ret(e) | mdo (Θ; e) | doall(e) | l | new(e) | get(e) | set(e1, e2) | e1 + e2 | freezeX (e) | e \ X | [ι ; ∆] with ι injective and dom(ι) ∩ DV (∆) = ∅ Θ: : = ∅ | Θ, x ⇐ e with x ∈ DV (Θ) ∆: : = ∅ | ∆, D with DV (∆) ∩ DV (D) = DN (∆) ∩ DN (D) = ∅ D: : = X ✁ e | x ✁ e with ✁ either = or ⇐ where: X ∈ Name (component) names x ∈ Var variables l ∈ L locations ι: Var

fin

→ Name is an input assignment

  • : Name

fin

→ Exp is an output assignment ρ: Var

fin

→ Exp is a local assignment [DV (_) , DN (_) , FV(_) definition for D, ∆ and Θ]

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.16/28

slide-43
SLIDE 43

Type system

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.17/28

slide-44
SLIDE 44

Type system

Types: τ ∈ T : : = . . . | Mτ | refτ | {Π} | [Π; Π′] where Π: Name

fin

→ T Judgment: Γ ⊢Σ e: τ “e is a well-typed term of type τ in Γ and Σ” with Γ: Var

fin

→ T type assignment Σ: L

fin

→ T signature for locations

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.17/28

slide-45
SLIDE 45

Type system

Types: τ ∈ T : : = . . . | Mτ | refτ | {Π} | [Π; Π′] where Π: Name

fin

→ T Judgment: Γ ⊢Σ e: τ “e is a well-typed term of type τ in Γ and Σ” with Γ: Var

fin

→ T type assignment Σ: L

fin

→ T signature for locations Rules:

(var)

Γ ⊢Σ x: τ Γ(x) = τ

(ret)

Γ ⊢Σ e: τ Γ ⊢Σ ret(e): Mτ

(mdo)

{Γ, ΓΘ ⊢Σ e: Mτ | (x ⇐ e) ∈ Θ ∧ τ = ΓΘ(x)} Γ, ΓΘ ⊢Σ e′: Mτ ′ Γ ⊢Σ mdo (Θ; e′) : Mτ ′ dom(ΓΘ) = DV (Θ)

(let)

{Γ, Γρ ⊢Σ e: τ | e = ρ(x) ∧ τ = Γρ(x)} Γ, Γρ ⊢Σ e′: τ Γ ⊢Σ let(ρ; e′): τ dom(Γρ) = dom(ρ)

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.17/28

slide-46
SLIDE 46

Type system

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.18/28

slide-47
SLIDE 47

Type system

(l)

Γ ⊢Σ l: refτ Σ(l) = τ

(new)

Γ ⊢Σ e: τ Γ ⊢Σ new(e): M(refτ)

(get)

Γ ⊢Σ e: refτ Γ ⊢Σ get(e): Mτ

(set)

Γ ⊢Σ e2: τ Γ ⊢Σ e1: refτ Γ ⊢Σ set(e1, e2): M(refτ)

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.18/28

slide-48
SLIDE 48

Type system

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.19/28

slide-49
SLIDE 49

Type system

(mixin)

{Γ, Γ1, Γ2 ⊢Σ e: τ | (X = e) ∈ ∆ ∧ τ = Π′(X)} {Γ, Γ1, Γ2 ⊢Σ e: Mτ | (X ⇐ e) ∈ ∆ ∧ τ = Π′(X)} {Γ, Γ1, Γ2 ⊢Σ e: τ | (x = e) ∈ ∆ ∧ τ = Γ2(x)} {Γ, Γ1, Γ2 ⊢Σ e: Mτ | (x ⇐ e) ∈ ∆ ∧ τ = Γ2(x)} Γ ⊢Σ [ι ; ∆]: [Π; Π′] img(ι) = dom(Π) Γ1

= Π ◦ ι DN (∆) = dom(Π′) DV (∆) = dom(Γ2)

(doall)

Γ ⊢Σ e: [∅; Π] Γ ⊢Σ doall(e): M{Π}

(record)

{Γ ⊢Σ e: τ | e = o(X) ∧ τ = Π(X)} Γ ⊢Σ {o}: {Π} dom(Π) = dom(o)

(select)

Γ ⊢Σ e: {Π} Γ ⊢Σ e.X: τ τ = Π(X)

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.19/28

slide-50
SLIDE 50

Type system

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.20/28

slide-51
SLIDE 51

Type system

(sum)

Γ ⊢Σ e1: [Π1; Π′

1]

Γ ⊢Σ e2: [Π2; Π′

2]

Γ ⊢Σ e1 + e2: [Π1, Π2; Π′

1, Π′ 2]

Π1 compatible with Π2 dom(Π′

1) ∩ dom(Π′ 2) = ∅

(freeze)

Γ ⊢Σ e: [Π; Π′] Γ ⊢Σ freezeX (e) : [Π \ X; Π′] Π(X) = Π′(X)

(delete)

Γ ⊢Σ e: [Π; Π′] Γ ⊢Σ e \ X: [Π; Π′ \ X] X ∈ dom(Π′)

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.20/28

slide-52
SLIDE 52

Simplification

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.21/28

slide-53
SLIDE 53

Simplification

(R) {o}.X > e provided e = o(X) (L) let(ρ; e) > e{x: let(ρ; ρ(x))|x ∈ dom(ρ)} (S) [ι1 ; ∆1] + [ι2 ; ∆2] > [ι1, ι2 ; ∆1, ∆2] provided [ι1, ι2 ; ∆1, ∆2] is well-formed, i.e. DN (∆1) ∩ DN (∆2) = DV (∆1) ∩ DV (∆2) = dom(ι1, ι2) ∩ DV (∆1, ∆2) = ∅ ι1, ι2 is an injection (therefore ι1 is compatible with ι2) FV(∆1) ∩ (dom(ι2) ∪ DV (∆2)) = FV(∆2) ∩ (dom(ι1) ∪ DV (∆1)) = ∅ (F) freezeX ([ι, x: X ; ∆, X ✁ e, ∆′]) > [ι ; ∆, x ✁ e, X = x, ∆′] (D) [ι ; ∆, X ✁ e, ∆′] \ X > [ι ; ∆, ∆′] [DV (_) , DN (_) , FV(_) definition for D, ∆ and Θ]

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.21/28

slide-54
SLIDE 54

Simplification

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.22/28

slide-55
SLIDE 55

Simplification

(A) doall([∅ ; ∆]) > mdo (|∆|; ret{o1, o2}){x: let(ρ; x)|x ∈ dom(ρ)} where ρ = {x: e|(x = e) ∈ ∆}

  • 1 = {X: e|(X = e) ∈ ∆} and
  • 2 = {X: xX|X ⇐ e ∈ ∆}, with xX freshly chosen

|∆| is defined by induction on ∆ as follows: |∅| = ∅ |(∆, X = e)| = |(∆, x = e)| = |∆| |(∆, X ⇐ e)| = |∆|, xX ⇐ e |(∆, x ⇐ e)| = |∆|, x ⇐ e

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.22/28

slide-56
SLIDE 56

Computation

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.23/28

slide-57
SLIDE 57

Computation

Stores: µ ∈ S

= L

fin

→ Exp Evaluation Contexts: E ∈ EC: : = ✷ | E[mdo (x ⇐ ✷, Θ; e)] configuration: (µ, e, E) ∈ Conf

= S × Exp × EC Bad terms: b ∈ BE : : = x | b + e | e + b | freezeX (b) | b \ X | doall(b) | b.X | get(b) | set(b, e) Computational Redexes: r ∈ R : : = mdo (Θ; e) | ret(e) | new(e) | get(l) | set(l, e) | b

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.23/28

slide-58
SLIDE 58

Computation

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.24/28

slide-59
SLIDE 59

Computation

Completion step: (done) (µ, ret(e), ✷) > done

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.24/28

slide-60
SLIDE 60

Computation

Completion step: (done) (µ, ret(e), ✷) > done Recursive monadic binding steps: (M.0) (µ, mdo (∅; e) , E) > (µ, e, E) (M.1) (µ, mdo (x1 ⇐ e1, Θ; e) , E) > (µ, e1, E[mdo (x1 ⇐ ✷, Θ; e)]), with variables in DV (x1 ⇐ e1, Θ) renamed to avoid clashes with CV (E) (M.2) (µ, ret(e1), E[mdo (x1 ⇐ ✷; e)]) > (µ{ρ}, e{ρ}, E), with ρ

= {x1: let(x1: e1; x1)} (M.3) (µ, ret(e1), E[mdo (x1 ⇐ ✷, x2 ⇐ e2, Θ; e)]) > (µ{ρ}, e2{ρ}, E[mdo (x2 ⇐ ✷, Θ; e){ρ}]), with ρ

= {x1: let(x1: e1; x1)} [CV (_) definition]

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.24/28

slide-61
SLIDE 61

Computation

Completion step: (done) (µ, ret(e), ✷) > done Recursive monadic binding steps: (M.0) (µ, mdo (∅; e) , E) > (µ, e, E) (M.1) (µ, mdo (x1 ⇐ e1, Θ; e) , E) > (µ, e1, E[mdo (x1 ⇐ ✷, Θ; e)]), with variables in DV (x1 ⇐ e1, Θ) renamed to avoid clashes with CV (E) (M.2) (µ, ret(e1), E[mdo (x1 ⇐ ✷; e)]) > (µ{ρ}, e{ρ}, E), with ρ

= {x1: let(x1: e1; x1)} (M.3) (µ, ret(e1), E[mdo (x1 ⇐ ✷, x2 ⇐ e2, Θ; e)]) > (µ{ρ}, e2{ρ}, E[mdo (x2 ⇐ ✷, Θ; e){ρ}]), with ρ

= {x1: let(x1: e1; x1)} [CV (_) definition] Imperative steps: (I.1) (µ, new(e), E) > (µ{l: e}, ret(l), E), l ∈ dom(µ) (I.2) (µ, get(l), E) > (µ, ret(e), E), e = µ(l) (I.3) (µ, set(l, e), E) > (µ{l: e}, ret(l), E), l ∈ dom(µ)

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.24/28

slide-62
SLIDE 62

Computation

Completion step: (done) (µ, ret(e), ✷) > done Recursive monadic binding steps: (M.0) (µ, mdo (∅; e) , E) > (µ, e, E) (M.1) (µ, mdo (x1 ⇐ e1, Θ; e) , E) > (µ, e1, E[mdo (x1 ⇐ ✷, Θ; e)]), with variables in DV (x1 ⇐ e1, Θ) renamed to avoid clashes with CV (E) (M.2) (µ, ret(e1), E[mdo (x1 ⇐ ✷; e)]) > (µ{ρ}, e{ρ}, E), with ρ

= {x1: let(x1: e1; x1)} (M.3) (µ, ret(e1), E[mdo (x1 ⇐ ✷, x2 ⇐ e2, Θ; e)]) > (µ{ρ}, e2{ρ}, E[mdo (x2 ⇐ ✷, Θ; e){ρ}]), with ρ

= {x1: let(x1: e1; x1)} [CV (_) definition] Imperative steps: (I.1) (µ, new(e), E) > (µ{l: e}, ret(l), E), l ∈ dom(µ) (I.2) (µ, get(l), E) > (µ, ret(e), E), e = µ(l) (I.3) (µ, set(l, e), E) > (µ{l: e}, ret(l), E), l ∈ dom(µ) Error step caused by a bad term: (err) (µ, b, E) > err

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.24/28

slide-63
SLIDE 63

Technical results

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.25/28

slide-64
SLIDE 64

Technical results

CR for > : The relation > is confluent SR for > : If Γ ⊢Σ e: τ and e > e′, then Γ ⊢Σ e′: τ Bisimulation: If (µ1, r1, E1)

∗> (µ2, r2, E2), then

  • 1. (µ1, r1, E1)

> Id1 implies ∃Id 2 s.t. (µ2, r2, E2) > Id2 and Id1

∗> Id2

  • 2. (µ2, r2, E2)

> Id2 implies ∃Id 1 s.t. (µ1, r1, E1) > Id1 and Id1

∗> Id2

where Id 1 and Id 2 range over Conf ∪ {done, err}. SR:

  • 1. If Γ ⊢Σ (µ, e, E) and (µ, e, E)

> (µ′, e′, E′), then Γ ⊢Σ (µ′, e′, E′).

  • 2. If Γ ⊢Σ (µ, e, E) and (µ, e, E)

> (µ′, e′, E′), then there exist Σ′ ⊇ Σ and Γ′ compatible with Γ such that Γ′ ⊢Σ′ (µ′, e′, E′). Progress: If Γ ⊢Σ (µ, e, E), then

  • 1. e ∈ R and (µ, e, E)

> , or

  • 2. e ∈ R and e

> [Γ ⊢Σ (µ, e, E): well-formed configuration definition]

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.25/28

slide-65
SLIDE 65

Definitions: functions function FV(_), DV (_) and DN (_)

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.26/28

slide-66
SLIDE 66

Definitions: functions function FV(_), DV (_) and DN (_)

e ∈ Exp FV(_) ⊆fin Var x {x} l ∅ ret(e) | new(e) | get(e) doall(e) | e.X | freezeX (e) | e \ X FV(e) set(e1, e2) | e1 + e2 FV(e1) ∪ FV(e2) mdo (Θ; e) (FV(Θ) ∪ FV(e)) \ DV (Θ) let(ρ; e) (FV(ρ) ∪ FV(e)) \ dom(ρ) {o} FV(o) [ι ; ∆] FV(∆) \ (DV (∆) ∪ dom(ι)) FV(f)

= ∪{FV(f(a))| a ∈ dom(f)} with f: A

fin

→ Exp D/∆/Θ FV(_) ⊆fin Var DV (_) ⊆fin Var DN (_) ⊆fin Name X ✁ e FV(e) ∅ {X} x ✁ e FV(e) {x} ∅ ∅ ∅ ∅ ∅ ∆, D FV(∆) ∪ FV(D) DV (∆) ∪ DV (D) DN (∆) ∪ DN (D) Θ, x ⇐ e FV(Θ) ∪ FV(e) DV (Θ) ∪ {x} ∅

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.26/28

slide-67
SLIDE 67

Definitions: functions FV(_) and CV (_) for E

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.27/28

slide-68
SLIDE 68

Definitions: functions FV(_) and CV (_) for E

E ∈ EC FV(_) ⊆fin Var CV (_) ⊆fin Var ✷ ∅ ∅ E[mdo (x ⇐ ✷, Θ; e)] FV(E) ∪ (FV(Θ, e)\ CV (E[mdo (x ⇐ ✷, Θ; e)])) CV (E) ∪ {x} ∪ DV (Θ)

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.27/28

slide-69
SLIDE 69

Definitions: well-formed configurations

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.28/28

slide-70
SLIDE 70

Definitions: well-formed configurations

Γ ⊢Σ (µ, e, E)

⇐ ⇒ dom(Σ) = dom(µ) and dom(Γ) = CV (E) µ(l) = el and Σ(l) = τl imply Γ ⊢Σ el: τl exists τ such that Γ ⊢Σ e: Mτ derivable exists τ ′ such that Γ, ✷: Mτ ⊢Σ E: Mτ ′ (i.e., it is well-formed) where: Well-formed evaluation context:

(✷)

∅, ✷: Mτ ⊢Σ ✷: Mτ

(mdo)

{Γ, x1: τ1, ΓΘ ⊢Σ e′: Mτ ′ | (x′ ⇐ e′) ∈ Θ ∧ τ ′ = ΓΘ(x′)} Γ, x1: τ1, ΓΘ ⊢Σ e: Mτ2 Γ, ✷: Mτ2 ⊢Σ E: Mτ Γ, x1: τ1, ΓΘ, ✷: Mτ1 ⊢Σ E[mdo (x1 ⇐ ✷, Θ; e)]: Mτ dom(ΓΘ) = DV (Θ)

Back to the Summary

APPSEM 2003 Mixin Modules and Computational Effects Sonia Fagorzi – p.28/28