H OW TO INCORPORATE EFFECTS ? Effects are . . . global store (i.e. - - PowerPoint PPT Presentation
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
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
Introduction Approach Expressiveness Conclusion
HOW TO INCORPORATE EFFECTS?
Effects are . . .
◮ global store (i.e. references), ◮ exceptions, ◮ I/O, ◮ random, ◮ nondeterminism, ◮ or concurrency 3
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
Introduction Approach Expressiveness Conclusion
WOULD BE COOL: User definable effects on top of a functional language There is more than one solution available!
5
Introduction Approach Expressiveness Conclusion
GOAL
Compare two existing approaches in their expressiveness A bit like “Compare expressiveness of recursion and for-loops”
6
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
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)
Introduction Approach Expressiveness Conclusion
ADD EACH CONCEPT
◮ Effects and handler calculus λeff ◮ Monadic reflection calculus λmon 9 Kammar, Lindley, and Oury (2013), Filinski (2010)
Introduction Approach Expressiveness Conclusion
EFFECT HANDLERS
10
Introduction Approach Expressiveness Conclusion
MONADIC REFLECTION
11
Introduction Approach Expressiveness Conclusion
DENOTATIONAL SEMANTICS
◮ Define what types “mean” in pure set theory ◮ Define what terms “mean” in pure set theory 12
Introduction Approach Expressiveness Conclusion
ADEQUACY AND SOUNDNESS
13
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)
Introduction Approach Expressiveness Conclusion
FOCUS IN THIS THESIS
Produce negative results: Prove that no translation exists with the help of denotational semantics
15
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
Introduction Approach Expressiveness Conclusion
THE BIG PICTURE
17
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
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
Introduction Approach Expressiveness Conclusion