a functional correspondence between evaluators and
play

A Functional Correspondence between Evaluators and Abstract Machines - PowerPoint PPT Presentation

A Functional Correspondence between Evaluators and Abstract Machines Mads Sig Ager, Dariusz Biernacki, Olivier Danvy , and Jan Midtgaard BRICS, University of Aarhus, Denmark BRICS Nottingham, March 28, 2003 1 Our message A correspondence


  1. A Functional Correspondence between Evaluators and Abstract Machines Mads Sig Ager, Dariusz Biernacki, Olivier Danvy , and Jan Midtgaard BRICS, University of Aarhus, Denmark BRICS Nottingham, March 28, 2003 1

  2. Our message A correspondence between evaluators and abstract machines by • closure conversion, • CPS transformation, and • defunctionalization. 2

  3. Our results • Krivine’s machine, • the CEK machine and variants, • the CLS machine, • the SECD machine, • the Categorical Abstract Machine, and more. 3

  4. My presentational problem Continuations. 4

  5. This talk A new attempt to explain continuations. 5

  6. BRICS The Two Disguises of Continuations Olivier Danvy and Lasse R. Nielsen BRICS, University of Aarhus, Denmark (danvy@brics.dk) Nottingham, March 28, 2003 6

  7. What are continuations? Take 1: A functional representation of the evaluation context. 7

  8. What are continuations? Take 2: A functional representation of the rest of the computation. 8

  9. Together Take 1: A functional representation of the evaluation context. Take 2: A functional representation of the rest of the computation. 9

  10. Goal of this talk To reconcile these two views: • continuations as evaluation contexts, and • continuations as the rest of the computation. 10

  11. Tool: Syntactic Theories A small-step operational semantics with an explicit representation of the evaluation context. Ideal to specify control operators. 11

  12. • Notion of term, notion of value. • Evaluation contexts: decomposition, plugging. • Unique-decomposition lemma (for deterministic languages). • Redexes and reduction rules. • One-step reduction: decompose, contract, and plug. 12

  13. Syntactic theories: Quo Vadis? • A small-step operational semantics with evaluation contexts. • Origin: Felleisen’s PhD thesis (1987). • Largely used since. • Practical challenges: evaluation contexts and unique-decomposition lemma. 13

  14. A programming experiment (1/2) Write a one-step reduction function: exp → val + exp • Compositional, first order, direct style. • Recursive descent: calls decompose, returns (re)construct. 14

  15. A programming experiment (2/2) • CPS-transform the one-step reducer: exp × ( val + exp → α ) → α • Defunctionalize the continuation into: – a data type, and – an apply function. 15

  16. And then a miracle happens • The data type is that of evaluation contexts. (And in hindsight what else could it be?) • The apply function is the plug function. 16

  17. And then a miracle happens • The data type is that of evaluation contexts. (And in hindsight what else could it be?) • The apply function is the plug function. So continuations do represent evaluation contexts. 17

  18. Byproducts • Mechanically deriving a syntactic theory from a one-step reduction function. • If the reduction function is compositional then the unique-decomposition lemma is guaranteed to hold. 18

  19. Evaluation Evaluation: The transitive closure of one-step reduction. ( decompose, contract, plug ) ∗ 19

  20. Deforestation Replace decompose, contract, plug, decompose, contract, plug, ... by decompose, contract, refocus, contract, refocus, contract, ... 20

  21. Reference Olivier Danvy and Lasse R. Nielsen “Syntactic Theories in Practice” BRICS RS-02-04 21

  22. And then another miracle happens The data type of evaluation contexts and the refocus function are in defunctionalized form. 22

  23. And then another miracle happens The data type of evaluation contexts and the refocus function are in defunctionalized form. The corresponding higher-order program is a compositional evaluator in CPS . 23

  24. And then another miracle happens The data type of evaluation contexts and the refocus function are in defunctionalized form. The corresponding higher-order program is a compositional evaluator in CPS . So continuations do represent the rest of the computation. 24

  25. Byproducts • Mechanically deriving a syntactic theory from an evaluation function. • Mechanically deriving an abstract machine from an evaluation function. 25

  26. Syntactic theories for the λ -calculus 1. Pick your favorite monad. 2. Write the corresponding functional evaluator (by inlining the monad in an evaluator for the computational λ -calculus). 3. Mechanically construct the corresponding syntactic theory and its abstract machine. 26

  27. Conclusions • Continuations represent evaluation contexts for one-step reduction. • Continuations represent the rest of the computation for evaluation. • Syntactic theories can be constructed from one-step reduction functions and from evaluation functions. 27

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend