Reflection and Hyper-Programming in Persistent Programming Systems”

Total Page:16

File Type:pdf, Size:1020Kb

Reflection and Hyper-Programming in Persistent Programming Systems” This thesis should be referenced as: Kirby, G.N.C. “Reflection and Hyper-Programming in Persistent Programming Systems”. Ph.D. Thesis, University of St Andrews (1992). Reflection and Hyper-Programming in Persistent Programming Systems Graham N. C. Kirby Department of Mathematical and Computational Sciences University of St Andrews St Andrews Fife KY16 9SS Scotland Abstract In an orthogonally persistent programming system, data is treated in a manner independent of its persistence. This gives simpler semantics, allows the programmer to ignore details of long-term data storage and enables type checking protection mechanisms to operate over the entire lifetime of the data. The ultimate goal of persistent programming language research is to reduce the costs of producing software. The work presented in this thesis seeks to improve programmer productivity in the following ways: • by reducing the amount of code that has to be written to construct an application; • by increasing the reliability of the code written; and • by improving the programmer’s understanding of the persistent environment in which applications are constructed. Two programming techniques that may be used to pursue these goals in a persistent environment are type-safe linguistic reflection and hyper-programming. The first provides a mechanism by which the programmer can write generators that, when executed, produce new program representations. This allows the specification of programs that are highly generic yet depend in non-trivial ways on the types of the data on which they operate. Genericity promotes software reuse which in turn reduces the amount of new code that has to be written. Hyper-programming allows a source program to contain links to data items in the persistent store. This improves program reliability by allowing certain program checking to be performed earlier than is otherwise possible. It also reduces the amount of code written by permitting direct links to data in the place of textual descriptions. Both techniques contribute to the understanding of the persistent environment through supporting the implementation of store browsing tools and allowing source representations to be associated with all executable programs in the persistent store. This thesis describes in detail the structure of type-safe linguistic reflection and hyper- programming, their benefits in the persistent context, and a suite of programming tools that support reflective programming and hyper-programming. These tools may be used in conjunction to allow reflection over hyper-program representations. The implementation of the tools is described. Acknowledgements I thank my supervisor Ron Morrison for his support, guidance and enthusiasm. He has succeeded in providing a superb research environment. Ron Morrison, Richard Connor, Quintin Cutts, Al Dearle and Dave Stemple have all been directly involved in the research described in this thesis. I thank them and the other members of the PISA group at St Andrews, Fred Brown, Dave Munro and Craig Baker, for the benefits of numerous discussions. I have also been helped by talking with Alex Farkas, Tim Sheard, John Rosenberg and Malcolm Atkinson. Ron Morrison, Dave Stemple and Richard Connor provided invaluable constructive criticism during the writing of this thesis. Thanks to Al for luring me into computing research in the first place with his diving trip tales of browser writing. Finally I thank Charlotte for always cheering me up. Contents 1 Introduction .......................................................................................................... 1 1.1 Persistence and Software Costs................................................................... 1 1.2 The FIDE View of Software Production..................................................... 2 1.3 Persistence as a Platform............................................................................. 3 1.3.1 Writing Less Code ............................................................................. 3 1.3.2 Writing More Reliable Code.............................................................. 4 1.3.3 Understanding the Persistent Environment........................................ 4 1.3.4 Research Topics ................................................................................. 4 1.4 Linguistic Reflection................................................................................... 5 1.5 Hyper-Programming ................................................................................... 5 1.6 Software Products ....................................................................................... 6 1.7 Thesis Structure........................................................................................... 6 2 Reflection ............................................................................................................. 7 2.1 Introduction ................................................................................................. 7 2.1.1 Behavioural Reflection ...................................................................... 7 2.1.2 Linguistic Reflection.......................................................................... 8 2.1.2.1 Characterisation ........................................................................ 8 2.1.2.2 Lisp............................................................................................ 8 2.1.2.3 POP-2 ........................................................................................ 9 2.1.2.4 TRPL ....................................................................................... 10 2.1.2.5 PS-algol ................................................................................... 11 2.1.2.6 Napier88.................................................................................. 13 2.2 Type-Safe Linguistic Reflection ............................................................... 14 2.3 Anatomy of Type-Safe Linguistic Reflection ........................................... 16 2.3.1 Reflection in General ....................................................................... 16 2.3.2 Compilation...................................................................................... 19 2.3.3 Compile-Time Linguistic Reflection ............................................... 20 2.3.4 Optimised Compile-Time Linguistic Reflection.............................. 21 2.3.5 Run-Time Linguistic Reflection ...................................................... 23 2.3.6 Combined Compile-Time and Run-Time Linguistic Reflection ..... 25 2.4 Dimensions of Type-Safe Linguistic Reflection....................................... 25 2.4.1 Initiation of Reflection ..................................................................... 26 2.4.2 Time of Generator Execution........................................................... 26 2.4.3 Nature of Generators ........................................................................ 26 2.4.4 Execution Environment of Generators............................................. 26 2.4.5 Time of Type Checking of Generated Code .................................... 27 2.4.6 Execution Environment of Generated Code .................................... 27 2.4.7 Linking Generated Code into the Original Program ........................ 27 2.4.8 Characterisation of TRPL, PS-algol and Napier88 .......................... 27 2.4.8.1 TRPL ....................................................................................... 27 2.4.8.2 PS-algol ................................................................................... 28 2.4.8.3 Napier88.................................................................................. 29 2.5 Applications of Type-Safe Linguistic Reflection ..................................... 30 2.5.1 Genericity and Efficiency ................................................................ 30 2.5.2 Software Evolution in Persistent Systems ....................................... 32 2.5.3 Implementing Data Models.............................................................. 35 2.5.4 Optimising Implementations............................................................ 35 2.5.5 Validating Specifications ................................................................. 35 2.6 Anatomy of Generators ............................................................................. 36 2.6.1 Generator Components .................................................................... 36 2.6.2 Components in TRPL Generators .................................................... 37 2.6.3 Components in PS-algol Generators ................................................ 37 2.6.4 Components in Napier88 Generators ............................................... 38 2.6.5 Factors in Understanding Generators............................................... 39 2.7 Research Areas.......................................................................................... 39 2.8 Conclusions ............................................................................................... 40 3 Hyper-Programming .......................................................................................... 42 3.1 Introduction ............................................................................................... 42 3.2 Motivations and Benefits .......................................................................... 44 3.2.1 Program Composition ...................................................................... 44 3.2.2 Early Checking................................................................................
Recommended publications
  • Structured Recursion for Non-Uniform Data-Types
    Structured recursion for non-uniform data-types by Paul Alexander Blampied, B.Sc. Thesis submitted to the University of Nottingham for the degree of Doctor of Philosophy, March 2000 Contents Acknowledgements .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 1 Chapter 1. Introduction .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 2 1.1. Non-uniform data-types .. .. .. .. .. .. .. .. .. .. .. .. 3 1.2. Program calculation .. .. .. .. .. .. .. .. .. .. .. .. .. 10 1.3. Maps and folds in Squiggol .. .. .. .. .. .. .. .. .. .. .. 11 1.4. Related work .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 14 1.5. Purpose and contributions of this thesis .. .. .. .. .. .. .. 15 Chapter 2. Categorical data-types .. .. .. .. .. .. .. .. .. .. .. .. 18 2.1. Notation .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 19 2.2. Data-types as initial algebras .. .. .. .. .. .. .. .. .. .. 21 2.3. Parameterized data-types .. .. .. .. .. .. .. .. .. .. .. 29 2.4. Calculation properties of catamorphisms .. .. .. .. .. .. .. 33 2.5. Existence of initial algebras .. .. .. .. .. .. .. .. .. .. .. 37 2.6. Algebraic data-types in functional programming .. .. .. .. 57 2.7. Chapter summary .. .. .. .. .. .. .. .. .. .. .. .. .. 61 Chapter 3. Folding in functor categories .. .. .. .. .. .. .. .. .. .. 62 3.1. Natural transformations and functor categories .. .. .. .. .. 63 3.2. Initial algebras in functor categories .. .. .. .. .. .. .. .. 68 3.3. Examples and non-examples .. .. .. .. .. .. .. .. .. .. 77 3.4. Existence of initial algebras in functor categories .. .. .. .. 82 3.5.
    [Show full text]
  • Binary Search Trees
    Introduction Recursive data types Binary Trees Binary Search Trees Organizing information Sum-of-Product data types Theory of Programming Languages Computer Science Department Wellesley College Introduction Recursive data types Binary Trees Binary Search Trees Table of contents Introduction Recursive data types Binary Trees Binary Search Trees Introduction Recursive data types Binary Trees Binary Search Trees Sum-of-product data types Every general-purpose programming language must allow the • processing of values with different structure that are nevertheless considered to have the same “type”. For example, in the processing of simple geometric figures, we • want a notion of a “figure type” that includes circles with a radius, rectangles with a width and height, and triangles with three sides: The name in the oval is a tag that indicates which kind of • figure the value is, and the branches leading down from the oval indicate the components of the value. Such types are known as sum-of-product data types because they consist of a sum of tagged types, each of which holds on to a product of components. Introduction Recursive data types Binary Trees Binary Search Trees Declaring the new figure type in Ocaml In Ocaml we can declare a new figure type that represents these sorts of geometric figures as follows: type figure = Circ of float (* radius *) | Rect of float * float (* width, height *) | Tri of float * float * float (* side1, side2, side3 *) Such a declaration is known as a data type declaration. It consists of a series of |-separated clauses of the form constructor-name of component-types, where constructor-name must be capitalized.
    [Show full text]
  • Recursive Type Generativity
    Recursive Type Generativity Derek Dreyer Toyota Technological Institute at Chicago [email protected] Abstract 1. Introduction Existential types provide a simple and elegant foundation for un- Recursive modules are one of the most frequently requested exten- derstanding generative abstract data types, of the kind supported by sions to the ML languages. After all, the ability to have cyclic de- the Standard ML module system. However, in attempting to extend pendencies between different files is a feature that is commonplace ML with support for recursive modules, we have found that the tra- in mainstream languages like C and Java. To the novice program- ditional existential account of type generativity does not work well mer especially, it seems very strange that the ML module system in the presence of mutually recursive module definitions. The key should provide such powerful mechanisms for data abstraction and problem is that, in recursive modules, one may wish to define an code reuse as functors and translucent signatures, and yet not allow abstract type in a context where a name for the type already exists, mutually recursive functions and data types to be broken into sepa- but the existential type mechanism does not allow one to do so. rate modules. Certainly, for simple examples of recursive modules, We propose a novel account of recursive type generativity that it is difficult to convincingly argue why ML could not be extended resolves this problem. The basic idea is to separate the act of gener- in some ad hoc way to allow them. However, when one considers ating a name for an abstract type from the act of defining its under- the semantics of a general recursive module mechanism, one runs lying representation.
    [Show full text]
  • S-Algol Reference Manual Ron Morrison
    S-algol Reference Manual Ron Morrison University of St. Andrews, North Haugh, Fife, Scotland. KY16 9SS CS/79/1 1 Contents Chapter 1. Preface 2. Syntax Specification 3. Types and Type Rules 3.1 Universe of Discourse 3.2 Type Rules 4. Literals 4.1 Integer Literals 4.2 Real Literals 4.3 Boolean Literals 4.4 String Literals 4.5 Pixel Literals 4.6 File Literal 4.7 pntr Literal 5. Primitive Expressions and Operators 5.1 Boolean Expressions 5.2 Comparison Operators 5.3 Arithmetic Expressions 5.4 Arithmetic Precedence Rules 5.5 String Expressions 5.6 Picture Expressions 5.7 Pixel Expressions 5.8 Precedence Table 5.9 Other Expressions 6. Declarations 6.1 Identifiers 6.2 Variables, Constants and Declaration of Data Objects 6.3 Sequences 6.4 Brackets 6.5 Scope Rules 7. Clauses 7.1 Assignment Clause 7.2 if Clause 7.3 case Clause 7.4 repeat ... while ... do ... Clause 7.5 for Clause 7.6 abort Clause 8. Procedures 8.1 Declarations and Calls 8.2 Forward Declarations 2 9. Aggregates 9.1 Vectors 9.1.1 Creation of Vectors 9.1.2 upb and lwb 9.1.3 Indexing 9.1.4 Equality and Equivalence 9.2 Structures 9.2.1 Creation of Structures 9.2.2 Equality and Equivalence 9.2.3 Indexing 9.3 Images 9.3.1 Creation of Images 9.3.2 Indexing 9.3.3 Depth Selection 9.3.4 Equality and Equivalence 10. Input and Output 10.1 Input 10.2 Output 10.3 i.w, s.w and r.w 10.4 End of File 11.
    [Show full text]
  • Data Structures Are Ways to Organize Data (Informa- Tion). Examples
    CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 1 ] What are Data Structures? Data structures are ways to organize data (informa- tion). Examples: simple variables — primitive types objects — collection of data items of various types arrays — collection of data items of the same type, stored contiguously linked lists — sequence of data items, each one points to the next one Typically, algorithms go with the data structures to manipulate the data (e.g., the methods of a class). This course will cover some more complicated data structures: how to implement them efficiently what they are good for CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 2 ] Abstract Data Types An abstract data type (ADT) defines a state of an object and operations that act on the object, possibly changing the state. Similar to a Java class. This course will cover specifications of several common ADTs pros and cons of different implementations of the ADTs (e.g., array or linked list? sorted or unsorted?) how the ADT can be used to solve other problems CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 3 ] Specific ADTs The ADTs to be studied (and some sample applica- tions) are: stack evaluate arithmetic expressions queue simulate complex systems, such as traffic general list AI systems, including the LISP language tree simple and fast sorting table database applications, with quick look-up CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 4 ] How Does C Fit In? Although data structures are universal (can be imple- mented in any programming language), this course will use Java and C: non-object-oriented parts of Java are based on C C is not object-oriented We will learn how to gain the advantages of data ab- straction and modularity in C, by using self-discipline to achieve what Java forces you to do.
    [Show full text]
  • Lecture Notes in Computer Science
    Orthogonal Persistence Revisited Alan Dearle, Graham N.C. Kirby and Ron Morrison School of Computer Science, University of St Andrews, North Haugh, St Andrews, Fife KY16 9SX, Scotland {al, graham, ron}@cs.st-andrews.ac.uk Abstract. The social and economic importance of large bodies of programs and data that are potentially long-lived has attracted much attention in the commercial and research communities. Here we concentrate on a set of methodologies and technologies called persistent programming. In particular we review programming language support for the concept of orthogonal persistence, a technique for the uniform treatment of objects irrespective of their types or longevity. While research in persistent programming has become unfashionable, we show how the concept is beginning to appear as a major component of modern systems. We relate these attempts to the original principles of orthogonal persistence and give a few hints about how the concept may be utilised in the future. 1 Introduction The aim of persistent programming is to support the design, construction, maintenance and operation of long-lived, concurrently accessed and potentially large bodies of data and programs. When research into persistent programming began, persistent application systems were supported by disparate mechanisms, each based upon different philosophical assumptions and implementation technologies [1]. The mix of technologies typically included naming, type and binding schemes combined with different database systems, storage architectures and query languages. The incoherence in these technologies increased the cost both intellectually and mechanically of building persistent application systems. The complexity distracted the application builder from the task in hand to concentrate on mastering the multiplicity of programming systems, and the mappings amongst them, rather than the application being developed.
    [Show full text]
  • Persistent Programming and Object Oriented Databases
    l.l Persistent Programming and Object Oriented Databases Malcolm Atkinson and Ronald Morrison University of Glasgow University of St. Andrews Abstract Persistent Programming Languages are defined as those languages which allow any of their values to have lives of any duration. The first ten years of research into those languages are reviewed. The motivation for such languages has increased. There are significant technological developments pertinent to their implementation. To obtain the ir benefits requires a radical revision of the architecture of computer systems, and a major comm itment to the parad igm . Their potential as a foundation for im plementing operating systems and database systems is described, as well as their obvious use for writing long-lived and large scale applications. The paper concludes by examining some aspects of object orientation, to consider the solutions offered by the persistent paradigm. 1 Introduction It is now ten years since a group in Scotland began the implementation of a persistent programming language. This paper reviews the progress in those ten years, and then suggests the next major step in persistent programming research. The review concludes that persistent programming languages have the capability of supporting applications programs and many components currently thought of as system components. The next step will demonstrate the value of persistent languages as a foundation for system software. It will also realise the target of 'seamless' computing which that research began to explore ten years ago, and provide efficient implementation of this class of languages. Such a seamless system is expected to yield very large productivity improvements for the implementers of large app lication systems.
    [Show full text]
  • This Thesis Has Been Submitted in Fulfilment of the Requirements for a Postgraduate Degree (E.G
    This thesis has been submitted in fulfilment of the requirements for a postgraduate degree (e.g. PhD, MPhil, DClinPsychol) at the University of Edinburgh. Please note the following terms and conditions of use: • This work is protected by copyright and other intellectual property rights, which are retained by the thesis author, unless otherwise stated. • A copy can be downloaded for personal non-commercial research or study, without prior permission or charge. • This thesis cannot be reproduced or quoted extensively from without first obtaining permission in writing from the author. • The content must not be changed in any way or sold commercially in any format or medium without the formal permission of the author. • When referring to this work, full bibliographic details including the author, title, awarding institution and date of the thesis must be given. EVALUATION OF FUNCTIONAL DATA MODELS FOR DATABASE DESIGN AND USE by KRISHNARAO GURURAO KULKARNI Ph. D. University of Edinburgh 1983 To my wife, Rama and daughter, Bhuvana Acknowledgements I am deeply indebted to my thesis supervisor, Dr. Malcolm Atkinson, for his constant guidance, help, and encouragement. for his highly incisive comments on the writing of this thesis, and for a host of other reasons. It is indeed a great pleasure to acknowledge his contribution. I am also greatly indebted to Dr. David Rees, who supervised me during the initial six months. His help and guidance during that time was invaluable. I am thankful to many of my friends In the Department for their kind advice from time to time. In particular, I would like to thank Paul Cockshott, Ken Chisholm, Pedro Hepp, Segun Owoso, George Ross, and Rob Procter for many useful discussions.
    [Show full text]
  • Recursive Type Generativity
    JFP 17 (4 & 5): 433–471, 2007. c 2007 Cambridge University Press 433 doi:10.1017/S0956796807006429 Printed in the United Kingdom Recursive type generativity DEREK DREYER Toyota Technological Institute, Chicago, IL 60637, USA (e-mail: [email protected]) Abstract Existential types provide a simple and elegant foundation for understanding generative abstract data types of the kind supported by the Standard ML module system. However, in attempting to extend ML with support for recursive modules, we have found that the traditional existential account of type generativity does not work well in the presence of mutually recursive module definitions. The key problem is that, in recursive modules, one may wish to define an abstract type in a context where a name for the type already exists, but the existential type mechanism does not allow one to do so. We propose a novel account of recursive type generativity that resolves this problem. The basic idea is to separate the act of generating a name for an abstract type from the act of defining its underlying representation. To define several abstract types recursively, one may first “forward-declare” them by generating their names, and then supply each one’s identity secretly within its own defining expression. Intuitively, this can be viewed as a kind of backpatching semantics for recursion at the level of types. Care must be taken to ensure that a type name is not defined more than once, and that cycles do not arise among “transparent” type definitions. In contrast to the usual continuation-passing interpretation of existential types in terms of universal types, our account of type generativity suggests a destination-passing interpretation.
    [Show full text]
  • Napier88 Reference Manual Release 2.2.1
    Napier88 Reference Manual Release 2.2.1 July 1996 Ron Morrison Fred Brown* Richard Connor Quintin Cutts† Alan Dearle‡ Graham Kirby Dave Munro University of St Andrews, North Haugh, St Andrews, Fife KY16 9SS, Scotland. *Department of Computer Science, University of Adelaide, South Australia 5005, Australia. †University of Glasgow, Lilybank Gardens, Glasgow G12 8QQ, Scotland. ‡University of Stirling, Stirling FK9 4LA, Scotland. This document should be referenced as: “Napier88 Reference Manual (Release 2.2.1)”. University of St Andrews (1996). Contents 1 INTRODUCTION ............................................................................. 5 2 CONTEXT FREE SYNTAX SPECIFICATION.......................................... 8 3 TYPES AND TYPE RULES ................................................................ 9 3.1 UNIVERSE OF DISCOURSE...............................................................................................9 3.2 THE TYPE ALGEBRA..................................................................................................... 10 3.2.1 Aliasing............................................................................................................... 10 3.2.2 Recursive Definitions............................................................................................. 10 3.2.3 Type Operators...................................................................................................... 11 3.2.4 Recursive Operators ..............................................................................................
    [Show full text]
  • Compositional Data Types
    Compositional Data Types Patrick Bahr Tom Hvitved Department of Computer Science, University of Copenhagen Universitetsparken 1, 2100 Copenhagen, Denmark {paba,hvitved}@diku.dk Abstract require the duplication of functions which work both on general and Building on Wouter Swierstra’s Data types `ala carte, we present a non-empty lists. comprehensive Haskell library of compositional data types suitable The situation illustrated above is an ubiquitous issue in com- for practical applications. In this framework, data types and func- piler construction: In a compiler, an abstract syntax tree (AST) tions on them can be defined in a modular fashion. We extend the is produced from a source file, which then goes through different existing work by implementing a wide array of recursion schemes transformation and analysis phases, and is finally transformed into including monadic computations. Above all, we generalise recur- the target code. As functional programmers, we want to reflect the sive data types to contexts, which allow us to characterise a special changes of each transformation step in the type of the AST. For ex- yet frequent kind of catamorphisms. The thus established notion of ample, consider the desugaring phase of a compiler which reduces term homomorphisms allows for flexible reuse and enables short- syntactic sugar to the core syntax of the object language. To prop- cut fusion style deforestation which yields considerable speedups. erly reflect this structural change also in the types, we have to create We demonstrate our framework in the setting of compiler con- and maintain a variant of the data type defining the AST for the core struction, and moreover, we compare compositional data types with syntax.
    [Show full text]
  • 4. Types and Polymorphism
    4. Types and Polymorphism Oscar Nierstrasz Static types ok Semantics ok Syntax ok Program text Roadmap > Static and Dynamic Types > Type Completeness > Types in Haskell > Monomorphic and Polymorphic types > Hindley-Milner Type Inference > Overloading References > Paul Hudak, “Conception, Evolution, and Application of Functional Programming Languages,” ACM Computing Surveys 21/3, Sept. 1989, pp 359-411. > L. Cardelli and P. Wegner, “On Understanding Types, Data Abstraction, and Polymorphism,” ACM Computing Surveys, 17/4, Dec. 1985, pp. 471-522. > D. Watt, Programming Language Concepts and Paradigms, Prentice Hall, 1990 3 Conception, Evolution, and Application of Functional Programming Languages http://scgresources.unibe.ch/Literature/PL/Huda89a-p359-hudak.pdf On Understanding Types, Data Abstraction, and Polymorphism http://lucacardelli.name/Papers/OnUnderstanding.A4.pdf Roadmap > Static and Dynamic Types > Type Completeness > Types in Haskell > Monomorphic and Polymorphic types > Hindley-Milner Type Inference > Overloading What is a Type? Type errors: ? 5 + [ ] ERROR: Type error in application *** expression : 5 + [ ] *** term : 5 *** type : Int *** does not match : [a] A type is a set of values? > int = { ... -2, -1, 0, 1, 2, 3, ... } > bool = { True, False } > Point = { [x=0,y=0], [x=1,y=0], [x=0,y=1] ... } 5 The notion of a type as a set of values is very natural and intuitive: Integers are a set of values; the Java type JButton corresponds to all possible instance of the JButton class (or any of its possible subclasses). What is a Type? A type is a partial specification of behaviour? > n,m:int ⇒ n+m is valid, but not(n) is an error > n:int ⇒ n := 1 is valid, but n := “hello world” is an error What kinds of specifications are interesting? Useful? 6 A Java interface is a simple example of a partial specification of behaviour.
    [Show full text]