Context-Aware Programming Languages

Context-Aware Programming Languages

UCAM-CL-TR-906 Technical Report ISSN 1476-2986 Number 906 Computer Laboratory Context-aware programming languages Tomas Petricek March 2017 15 JJ Thomson Avenue Cambridge CB3 0FD United Kingdom phone +44 1223 763500 http://www.cl.cam.ac.uk/ c 2017 Tomas Petricek This technical report is based on a dissertation submitted March 2017 by the author for the degree of Doctor of Philosophy to the University of Cambridge, Clare Hall. Technical reports published by the University of Cambridge Computer Laboratory are freely available via the Internet: http://www.cl.cam.ac.uk/techreports/ ISSN 1476-2986 ABSTRACT The development of programming languages needs to reflect important changes in the way programs execute. In recent years, this has included the development of parallel programming models (in reaction to the multi- core revolution) or improvements in data access technologies. This thesis is a response to another such revolution – the diversification of devices and systems where programs run. The key point made by this thesis is the realization that an execution en- vironment or a context is fundamental for writing modern applications and that programming languages should provide abstractions for programming with context and verifying how it is accessed. We identify a number of program properties that were not connected before, but model some notion of context. Our examples include tracking different execution platforms (and their versions) in cross-platform devel- opment, resources available in different execution environments (e. g. GPS sensor on a phone and database on the server), but also more traditional notions such as variable usage (e. g. in liveness analysis and linear logics) or past values in stream-based dataflow programming. Our first contribution is the discovery of the connection between the above examples and their novel presentation in the form of calculi (coeffect systems). The presented type systems and formal semantics highlight the relationship between dif- ferent notions of context. Our second contribution is the definition of two unified coeffect calculi that capture the common structure of the examples. In particular, our flat co- effect calculus models languages with contextual properties of the execution environment and our structural coeffect calculus models languages where the contextual properties are attached to the variable usage. We define the se- mantics of the calculi in terms of category theoretical structure of an indexed comonad (based on dualisation of the well-known monad structure), use it to define operational semantics and prove type safety of the calculi. Our third contribution is a novel presentation of our work in the form of web-based interactive essay. This provides a simple implementation of three context-aware programming languages and lets the reader write and run simple context-aware programs, but also explore the theory behind the implementation including the typing derivation and semantics. 3 ACKNOWLEDGEMENTS Thanks to: ALAN MYCROFT HDNORAAMPMM TARMO UUSTALU AOARDELIEYY DAN GHICA LMTNAOARTCO JEREMY GIBBONS LIOAIONORRR MARCELO FIORE GNWLREUSIOC DOMINIC ORCHARD IIFIGMLLCFH DON SYME SCUECHOAKTA RAOUL GABRIEL URMA TMASLLIVOER STEPHEN KELL EEPBELACVPD ANTRANIG BASMAN PGEEMPERARO SAM AARON HITTYLPKEIL LIESBETH DE MOL ENRHSESEUME GIUSEPPE PRIMIERO NAIYZINNLIC CLARE HALL ERCMYROAAER MATFYZ RTEEFBBMTRA DANIELA PETRICKOVA ONKRTABSSOM MIROSLAV PETRICEK IAVEAGIAUER FLIJMNGBUAU And most importantly: ............. CONTENTS i context-aware programming 11 1 why context-aware programming matters 13 1.1 Why context-aware programming matters . 14 1.1.1 Context awareness #1: Platform versioning . 15 1.1.2 Context awareness #2: System capabilities . 16 1.1.3 Context awareness #3: Confidentiality and provenance 17 1.1.4 Context-awareness #4: Checking array access patterns 17 1.2 Towards context-aware languages . 18 1.2.1 Context-aware languages in action . 19 1.2.2 Understanding context with types . 19 1.3 Theory of context dependence . 21 1.4 Thesis outline . 23 2 pathways to coeffects 25 2.1 Coeffects via static and dynamic binding . 25 2.1.1 Variable binding . 25 2.1.2 Implicit parameter binding . 26 2.1.3 Resolving ambiguity . 27 2.2 Coeffects via type and effect systems . 29 2.2.1 Simple effect system. 29 2.2.2 Simple coeffect system. 30 2.3 Coeffects via language semantics . 30 2.3.1 Effectful languages and meta-languages . 31 2.3.2 Marriage of effects and monads . 33 2.3.3 Context-dependent languages and meta-languages . 33 2.4 Coeffects via substructural and bunched logics . 37 2.4.1 Substructural type systems. 37 2.4.2 Bunched type systems. 38 2.5 Context oriented programming . 39 2.6 Summary . 39 3 context-aware systems 41 3.1 Structure of coeffect systems . 41 3.1.1 Effectful lambda abstraction . 42 3.1.2 Notions of context . 42 3.1.3 Scalars and vectors . 44 3.2 Flat coeffect systems . 45 3.2.1 Implicit parameters and type classes . 45 3.2.2 Distributed computing . 50 3.2.3 Liveness analysis . 53 3.2.4 Dataflow languages . 58 3.2.5 Permissions and safe locking . 63 3.3 Structural coeffect systems . 64 3.3.1 Liveness analysis revisited . 64 3.3.2 Bounded variable use . 69 3.3.3 Dataflow languages revisited . 72 3.3.4 Security, tainting and provenance . 75 3.4 Beyond passive contexts . 76 3.5 Summary . 78 7 8 contents ii coeffect calculi 79 4 types for flat coeffect calculus 83 4.1 Introduction . 83 4.1.1 A unified treatment of lambda abstraction . 84 4.2 Flat coeffect calculus . 84 4.2.1 Flat coeffect algebra . 85 4.2.2 Type system . 87 4.2.3 Understanding flat coeffects . 87 4.2.4 Examples of flat coeffects . 88 4.3 Choosing a unique typing . 90 4.3.1 Implicit parameters . 90 4.3.2 Dataflow and liveness . 93 4.4 Syntactic equational theory . 94 4.4.1 Syntactic properties . 94 4.4.2 Call-by-value evaluation . 95 4.4.3 Call-by-name evaluation . 97 4.5 Syntactic properties and extensions . 100 4.5.1 Subcoeffecting and subtyping . 100 4.5.2 Typing of let binding . 101 4.5.3 Properties of lambda abstraction . 102 4.5.4 Language with pairs and unit . 103 4.6 Summary . 104 5 semantics of flat coeffect calculus 105 5.1 Introduction and safety . 106 5.2 Categorical motivation . 107 5.2.1 Comonads are to coeffects what monads are to effects 107 5.2.2 Categorical semantics . 107 5.2.3 Introducing comonads . 108 5.2.4 Generalising to indexed comonads . 109 5.2.5 Flat indexed comonads . 111 5.2.6 Semantics of flat calculus . 114 5.3 Translational semantics . 116 5.3.1 Functional target language . 117 5.3.2 Safety of functional target language . 117 5.3.3 Comonadically-inspired translation . 119 5.4 Safety of context-aware languages . 121 5.4.1 Coeffect language for dataflow . 122 5.4.2 Coeffect language for implicit parameters . 124 5.5 Generalized safety of comonadic embedding . 128 5.6 Related categorical structures . 130 5.6.1 Indexed categorical structures . 131 5.6.2 When is a coeffect not a monad . 131 5.6.3 When is coeffect a monad . 132 5.7 Summary . 134 6 structural coeffect calculus 135 6.1 Introduction . 136 6.1.1 Related work . 136 6.2 Structural coeffect calculus . 136 6.2.1 Structural coeffect algebra . 137 6.2.2 Structural coeffect types . 138 6.2.3 Understanding structural coeffects . 140 6.2.4 Examples of structural coeffects . 140 6.3 Choosing a unique typing . 141 contents 9 6.3.1 Syntax-directed type system . 141 6.3.2 Properties . 143 6.4 Syntactic properties and extensions . 144 6.4.1 Let binding . 144 6.4.2 Subcoeffecting . 145 6.5 Syntactic equational theory . 145 6.5.1 From flat coeffects to structural coeffects . 146 6.5.2 Holes and substitution lemma . 147 6.5.3 Reduction and expansion . 148 6.6 Categorical motivation . 153 6.6.1 Indexed comonads, revisited . 153 6.6.2 Structural indexed comonads . 154 6.6.3 Semantics of structural calculus . 154 6.6.4 Examples of structural indexed comonads . 157 6.7 Translational semantics . 160 6.7.1 Comonadically-inspired language extensions . 160 6.7.2 Comonadically-inspired translation . 161 6.7.3 Structural coeffect language for dataflow . 163 6.8 Summary . 166 iii towards practical coeffects 169 7 implementation 171 7.1 From theory to implementation . 172 7.1.1 Type checking and inference . 172 7.1.2 Execution of context-aware programs . 173 7.1.3 Supporting additional context-aware languages . 174 7.2 Case studies . 174 7.2.1 Typing context-aware programs . 175 7.2.2 Comonadically-inspired translation . 175 7.3 Interactive essay . 177 7.3.1 Explorable language implementation . 178 7.3.2 Implementation overview . 180 7.4 Related work . 181 7.5 Summary . 182 8 unified coeffect systems 183 8.1 The unified coeffect calculus . 183 8.1.1 Shapes and containers . 184 8.1.2 Structure of coeffects . 185 8.1.3 Unified coeffect type system . 187 8.1.4 Structural coeffects . 189 8.1.5 Flat coeffects . 190 8.2 Coeffect meta-language . 192 8.2.1 Coeffects and contextual modal type theory . 192 8.2.2 Coeffect meta-language . 193 8.2.3 Embedding flat coeffect calculus . 195 8.3 Related and future work . 195 8.3.1 Embedded context-aware DSLs . 195 8.3.2 Extending the theory of coeffects . 197 8.4 Summary . ..

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    218 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us