Online Casino Canada Slots

  • Published on
    09-Jan-2017

  • View
    213

  • Download
    0

Embed Size (px)

Transcript

  • Technical ReportNumber 618

    Computer Laboratory

    UCAM-CL-TR-618ISSN 1476-2986

    The Fresh Approach:functional programmingwith names and binders

    Mark R. Shinwell

    February 2005

    15 JJ Thomson Avenue

    Cambridge CB3 0FD

    United Kingdom

    phone +44 1223 763500

    http://www.cl.cam.ac.uk/

  • c 2005 Mark R. Shinwell

    This technical report is based on a dissertation submittedDecember 2004 by the author for the degree of Doctor ofPhilosophy to the University of Cambridge, Queens College.

    Technical reports published by the University of CambridgeComputer Laboratory are freely available via the Internet:

    http://www.cl.cam.ac.uk/TechReports/

    ISSN 1476-2986

  • Abstract

    This report concerns the development of a language called Fresh Objective Caml, which isan extension of the Objective Caml language providing facilities for the manipulation of datastructures representing syntax involving -convertible names and binding operations.

    After an introductory chapter which includes a survey of related work, we describe theFresh Objective Caml language in detail. Next, we proceed to formalise a small core languagewhich captures the essence of Fresh Objective Caml; we call this Mini-FreshML. We providetwo varieties of operational semantics for this language and prove them equivalent. Then inorder to prove correctness properties of representations of syntax in the language we introducea new variety of domain theory called FM-domain theory, based on the permutation model ofname binding from Pitts and Gabbay. We show how classical domain-theoretic constructionsincluding those for the solution of recursive domain equationsfall naturally into this setting,where they are augmented by new constructions to handle name-binding.

    After developing the necessary domain theory, we demonstrate how it may be exploitedto give a monadic denotational semantics to Mini-FreshML. This semantics in itself is quitenovel and demonstrates how a simple monad of continuations is sufficient to model dynamicallocation of names. We prove that our denotational semantics is computationally adequatewith respect to the operational semanticsin other words, equality of denotation impliesobservational equivalence. After this, we show how the denotational semantics may be usedto prove our desired correctness properties.

    In the penultimate chapter, we examine the implementation of Fresh Objective Caml,describing detailed issues in the compiler and runtime systems. Then in the final chapterwe close the report with a discussion of future avenues of research and an assessment of thework completed so far.

    3

  • 4

  • Contents

    1 Introduction 7

    1.1 Other approaches to handle binding . . . . . . . . . . . . . . . . . . . . . . . . 9

    1.1.1 de Bruijn indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

    1.1.2 Threading of name states . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    1.1.3 Higher-order abstract syntax . . . . . . . . . . . . . . . . . . . . . . . . 10

    1.2 Other related work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    1.3 Report structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    2 Fresh Objective Caml 13

    2.1 Representation of object language names . . . . . . . . . . . . . . . . . . . . . . 13

    2.1.1 Bindable names: typing . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    2.1.2 Bindable names: creation . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    2.2 Representation of object language binding . . . . . . . . . . . . . . . . . . . . . 14

    2.2.1 Abstraction values: construction . . . . . . . . . . . . . . . . . . . . . . 15

    2.2.2 Abstraction values: typing . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    2.2.3 Abstraction values: deconstruction . . . . . . . . . . . . . . . . . . . . . 17

    2.2.4 Abstraction values: two sides of the same coin . . . . . . . . . . . . . . . 19

    2.2.5 Abstraction values: equality testing . . . . . . . . . . . . . . . . . . . . . 20

    2.3 Explicit atom-swapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    2.4 Fresh-for test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    2.5 Something missing? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    2.6 Reference cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    2.7 A full example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    2.8 Pretty-printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    3 Mini-FreshML, operationally 25

    3.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    3.2 Static semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

    3.3 Dynamic semantics via big-step . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

    3.4 Dynamic semantics via frame stacks . . . . . . . . . . . . . . . . . . . . . . . . . 30

    3.4.1 A termination relation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

    3.4.2 Relationship to the big-step semantics . . . . . . . . . . . . . . . . . . . 32

    3.5 Environment style semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

    3.6 Notions of observational equivalence . . . . . . . . . . . . . . . . . . . . . . . . 35

    3.7 Correctness for Mini-FreshML . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

    4 A domain theory for names 39

    4.1 FM-sets, FM-cpos and FM-cppos . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

    4.2 Some FM-cpos and their construction . . . . . . . . . . . . . . . . . . . . . . . . 41

    4.2.1 Atoms, lifting, products and sums . . . . . . . . . . . . . . . . . . . . . . 41

    4.2.2 Functions and function spaces . . . . . . . . . . . . . . . . . . . . . . . . 42

    4.2.3 Abstraction FM-cppos . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

    4.2.4 Some curiosities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

    4.3 Fixed points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

    4.4 Categorical constructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

    4.5 Solution of recursive equations on FM-cppos . . . . . . . . . . . . . . . . . . . . 50

    4.6 FM-sets of syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

    5

  • 6 CONTENTS

    5 Mini-FreshML, denotationally 555.1 An overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

    5.1.1 Dynamic allocation monads . . . . . . . . . . . . . . . . . . . . . . . . . 565.2 Definition of the denotational semantics . . . . . . . . . . . . . . . . . . . . . . 57

    5.2.1 Denotation of types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575.2.2 Denotation of expressions and frame stacks . . . . . . . . . . . . . . . . 58

    5.3 Some properties of the semantics . . . . . . . . . . . . . . . . . . . . . . . . . . 615.3.1 Support and equivariance properties . . . . . . . . . . . . . . . . . . . . 615.3.2 Substitutivity properties . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

    5.4 Computational adequacy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625.4.1 Construction of the logical relations . . . . . . . . . . . . . . . . . . . . 625.4.2 Relational structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635.4.3 Properties of the logical relations . . . . . . . . . . . . . . . . . . . . . . 685.4.4 Completing the proof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

    5.5 The road to equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775.6 Algebraic identities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795.7 Correctness of representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

    5.7.1 Background theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805.7.2 Correctness results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

    6 Implementation 876.1 Library, or bespoke system? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 876.2 System overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886.3 Creation of fresh names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886.4 Creation of abstraction values . . . . . . . . . . . . . . . . . . . . . . . . . . . . 896.5 Pattern-matching on abstraction values . . . . . . . . . . . . . . . . . . . . . . . 896.6 Implementation of swapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

    6.6.1 When to swap? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906.6.2 How to swap? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

    6.7 Preservation of sharing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936.8 Freshness inference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

    6.8.1 The motivation for a static analysis . . . . . . . . . . . . . . . . . . . . . 946.8.2 Static semantics with freshness inference . . . . . . . . . . . . . . . . . . 956.8.3 Purity analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986.8.4 A note on denotational semantics . . . . . . . . . . . . . . . . . . . . . . 986.8.5 An abstraction monad . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

    7 Conclusions and future work 1017.1 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101