H OW TO INCORPORATE EFFECTS ? Effects are . . . global store (i.e. - - PowerPoint PPT Presentation

h ow to incorporate effects
SMART_READER_LITE
LIVE PREVIEW

H OW TO INCORPORATE EFFECTS ? Effects are . . . global store (i.e. - - PowerPoint PPT Presentation

O N THE EXPRESSIVENESS OF EFFECT HANDLERS AND MONADIC REFLECTION Yannick Forster supvervised by Ohad Kammar and Marcelo Fiore Introduction Approach Expressiveness Conclusion A LITTLE SURVEY Who has ever tried to prove a functional program


slide-1
SLIDE 1

ON THE EXPRESSIVENESS OF EFFECT

HANDLERS AND MONADIC REFLECTION

Yannick Forster

supvervised by Ohad Kammar and Marcelo Fiore

slide-2
SLIDE 2

Introduction Approach Expressiveness Conclusion

A LITTLE SURVEY

◮ Who has ever tried to prove a functional program correct? ◮ Who has ever tried for a program involving reference cells

  • r exceptions?

◮ Who has succeeded? ◮ Who thought it was fun? 2

slide-3
SLIDE 3

Introduction Approach Expressiveness Conclusion

HOW TO INCORPORATE EFFECTS?

Effects are . . .

◮ global store (i.e. references), ◮ exceptions, ◮ I/O, ◮ random, ◮ nondeterminism, ◮ or concurrency 3

slide-4
SLIDE 4

Introduction Approach Expressiveness Conclusion

AN EXAMPLE

exception Error val r = ref 0 fun error () = raise Error fun test () = (r := 5; error() handle Error => !r) test() evaluates to?

Why not to 0?

4

slide-5
SLIDE 5

Introduction Approach Expressiveness Conclusion

WOULD BE COOL: User definable effects on top of a functional language There is more than one solution available!

5

slide-6
SLIDE 6

Introduction Approach Expressiveness Conclusion

GOAL

Compare two existing approaches in their expressiveness A bit like “Compare expressiveness of recursion and for-loops”

6

slide-7
SLIDE 7

Introduction Approach Expressiveness Conclusion

APPROACH

◮ take a base language (functional, typed, no recursion) ◮ add each concept to the language ◮ define denotational semantics to each resulting calculus ◮ prove denotational semantics to be adequate ◮ use this to compare expressiveness 7

slide-8
SLIDE 8

Introduction Approach Expressiveness Conclusion

TAKE A BASE LANGUAGE

Call-by-push-value lambda-calculus from Levy Distinguishes between values and computations

8 Levy (1999), Levy (2004)

slide-9
SLIDE 9

Introduction Approach Expressiveness Conclusion

ADD EACH CONCEPT

◮ Effects and handler calculus λeff ◮ Monadic reflection calculus λmon 9 Kammar, Lindley, and Oury (2013), Filinski (2010)

slide-10
SLIDE 10

Introduction Approach Expressiveness Conclusion

EFFECT HANDLERS

10

slide-11
SLIDE 11

Introduction Approach Expressiveness Conclusion

MONADIC REFLECTION

11

slide-12
SLIDE 12

Introduction Approach Expressiveness Conclusion

DENOTATIONAL SEMANTICS

◮ Define what types “mean” in pure set theory ◮ Define what terms “mean” in pure set theory 12

slide-13
SLIDE 13

Introduction Approach Expressiveness Conclusion

ADEQUACY AND SOUNDNESS

13

slide-14
SLIDE 14

Introduction Approach Expressiveness Conclusion

TYPED MACRO EXPRESSABILITY

One concept can express another if there is a local translation function that:

◮ is homomorphic on the base calculus ◮ replaces new syntactic constructs without rearranging the

whole program

◮ translates terms ∅ ⊢ M : X to terms ∅ ⊢ M : X 14 Felleisen (1990)

slide-15
SLIDE 15

Introduction Approach Expressiveness Conclusion

FOCUS IN THIS THESIS

Produce negative results: Prove that no translation exists with the help of denotational semantics

15

slide-16
SLIDE 16

Introduction Approach Expressiveness Conclusion

λmon CAN NOT TYPED MACRO EXPRESS λeff

◮ There are only finitely many terms for every type in λmon ◮ Some types in λeff have countably many observationally

distinguishable terms

◮ Given a translation λeff → λmon, take the type F1 ◮ F1 has k terms ◮ F1 has more than k observationally distinguishable terms ◮ Derive a contradiction 16

slide-17
SLIDE 17

Introduction Approach Expressiveness Conclusion

THE BIG PICTURE

17

slide-18
SLIDE 18

Introduction Approach Expressiveness Conclusion

CONTRIBUTION

◮ Adequacy proof for the set theoretic model for calculus of

effect handlers λeff

◮ Adequate denotational semantics for calculus of monadic

reflection λmon

◮ Definition of (typed) macro expressability ◮ Proof that λmon is macro expressible in λeff ◮ Proof that λeff is not macro typed expressible in λmon 18

slide-19
SLIDE 19

Introduction Approach Expressiveness Conclusion

FUTURE WORK

◮ Show that λmon is not typed macro expressible in λeff; ◮ extend the type system of λeff to typed macro express λmon; ◮ do similar comparison for calculus of delimited control. 19

slide-20
SLIDE 20

Introduction Approach Expressiveness Conclusion

RELATED WORK / BIBLIOGRAPHY

◮ Paul Blain Levy. Call-By-Push-Value: A

Functional/Imperative Synthesis, volume 2 of Semantics Structures in Computation. Springer, 2004.

◮ Ohad Kammar, Sam Lindley, and Nicolas Oury. Handlers

in action. SIGPLAN Not. 48(9):145–158, September 2013.

◮ Andrzej Filinski. Monads in action. SIGPLAN Not.,

45(1):483–494, January 2010.

◮ Matthias Felleisen. On the expressive power of

programming languages. In Science of Computer Programming, pages 134–151. Springer-Verlag, 1990.

20

slide-21
SLIDE 21

21

slide-22
SLIDE 22

22