Crafts

A functional correspondence between call-by-need evaluators and lazy abstract machines

Description
A functional correspondence between call-by-need evaluators and lazy abstract machines
Categories
Published
of 20
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  B RI   C S R S - 0  4  - 3  A  g e r  e  t   al    . :  C al   l   - b   y- N e  e  d E  v al    u a t   or  s  an d L  az   yA b  s  t  r  a c  t  M a c h i   n e  s  BRICS Basic Research in Computer Science A Functional Correspondence betweenCall-by-Need Evaluators andLazy Abstract Machines Mads Sig AgerOlivier DanvyJan MidtgaardBRICS Report Series RS-04-3ISSN 0909-0878 February 2004  Copyright c   2004, Mads Sig Ager & Olivier Danvy & JanMidtgaard.BRICS, Department of Computer ScienceUniversity of Aarhus. All rights reserved.Reproduction of all or part of this workis permitted for educational or research useon condition that this copyright notice isincluded in any copy.See back inner page fora listofrecent BRICS Report Series publications.Copies may be obtained by contacting:BRICSDepartment of Computer ScienceUniversity of AarhusNy Munkegade, building 540DK–8000 Aarhus CDenmarkTelephone:+45 8942 3360Telefax: +45 8942 3255Internet: BRICS@brics.dkBRICS publications are in general accessible through the World WideWeb and anonymous FTP through these URLs: http://www.brics.dkftp://ftp.brics.dk This document in subdirectory  RS/04/3/  A Functional Correspondencebetween Call-by-Need Evaluatorsand Lazy Abstract Machines  ∗ Mads Sig Ager, Olivier Danvy, and Jan MidtgaardBRICS † Department of Computer ScienceUniversity of Aarhus ‡ February 2004 Abstract We bridge the gap between compositional evaluators and abstract ma-chines for the lambda-calculus, using closure conversion, transformationinto continuation-passing style, and defunctionalization of continuations.This article is a followup of our article at PPDP 2003, where we considercall by name and call by value. Here, however, we consider call by need.We derive a lazy abstract machine from an ordinary call-by-need eval-uator that threads a heap of updatable cells. In this resulting abstractmachine, the continuation fragment for updating a heap cell naturallyappears as an ‘update marker’, an implementation technique that was in-vented for the Three Instruction Machine and subsequently used to con-struct lazy variants of Krivine’s abstract machine. Tuning the evaluatorleads to other implementation techniques such as unboxed values. Thecorrectness of the resulting abstract machines is a corollary of the correct-ness of the srcinal evaluators and of the program transformations usedin the derivation. ∗ To appear in Information Processing Letters (extended version). † Basic Research in Computer Science ( www.brics.dk ),funded by the Danish National Research Foundation. ‡ IT-parken, Aabogade 34, DK-8200 Aarhus N, Denmark.Email:  {  mads,danvy,jmi } @brics.dk 1  Contents 1 Background and introduction 32 From evaluator to abstract machine 3 2.1 A compositional evaluator . . . . . . . . . . . . . . . . . . . . . . 42.2 Representing call by need by threading a heap of updatable cells 52.3 Representing functions with closures . . . . . . . . . . . . . . . . 62.4 Representing control with continuations . . . . . . . . . . . . . . 72.5 Representing continuations using defunctionalization . . . . . . . 82.6 A lazy abstract machine . . . . . . . . . . . . . . . . . . . . . . . 10 3 Variants and extensions 114 Related work 115 Conclusion and issues 13 2  1 Background and introduction In previous work [1], we reported a simple derivation that makes it possible toderive Krivine’s machine from an ordinary call-by-name evaluator and Felleisenet al.’s CEK machine from an ordinary call-by-value evaluator, and to con-struct evaluators that correspond to Landin’s SECD machine, Hannan andMiller’s CLS machine, Schmidt’s VEC machine, and Curien et al.’s Categor-ical Abstract Machine. This derivation consists of three successive off-the-shelf program transformations: closure conversion, transformation into continuation-passing style (CPS), and Reynolds’s defunctionalization. By closure-convertingthe evaluator, its expressible, denotable, and storable values are made first or-der. By transforming it into continuation-passing style (CPS), its flow of controlis made manifest as a continuation. By defunctionalizing this continuation, theflow of control is materialized as a first-order data structure. The result is atransition function, i.e., an abstract machine. We are not aware of any otherderivation that accounts for independently designed evaluators and abstractmachines, even though closure conversion, CPS transformation, and defunc-tionalization are each far from being new and their combination can be found,e.g., in the textbook  Essentials of Programming Languages   [17, 18].The derivation also makes it possible to map refinements and variationsfrom an evaluator to the corresponding abstract machine. For example, onecan derive arbitrarily many “new” abstract machines by inlining monads in anevaluator expressed in Moggi’s computational meta-language [2]. One can alsoreflect refinements and variations from an abstract machine to the correspond-ing evaluator. For example, the optimization leading to a properly tail-recursiveSECD machine is not specific to abstract machines; it has a natural counter-part in the corresponding evaluator [10]. More generally, one can intervene atany point in the derivation to interject a concept and derive the correspondingevaluator and abstract machine.So far, we have only considered call by name and call by value. In the presentwork, we consider call by need and we derive a lazy abstract machine from acall-by-need evaluator. We then outline possible variants, review related work,and conclude. This article can be read independently of our earlier work. 2 From evaluator to abstract machine We start from a call-by-name evaluator for the  λ -calculus, written in StandardML [30]. To make it follow call by need [19, 23, 42], we thread a heap of updatable cells (Section 2.2). Threading this heap is akin to inlining a statemonad [2]. Using updatable cells to implement call by need is traditional [3,page 333] [36, page 176] [43, page 81]. We then closure-convert the evaluator(Section 2.3), CPS-transform it (Section 2.4), and defunctionalize the contin-uations (Section 2.5). The result is the transition functions of a lazy abstractmachine (Section 2.6).3
Search
Similar documents
View more...
Related Search
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks