
DOMAIN-THEORETIC FOUNDATIONS OF FUNCTIONAL PROGRAMMING Thomas Streicher DOMAIN-THEORETIC FOUNDATIONS OF FUNCTIONAL PROGRAMMING DOMAIN-THEORETIC FOUNDATIONS OF FUNCTIONAL PROGRAMMING Technical University Darmstadt, Germany 1t» World Scientific NEW ,JERSEY. LONDON· SINGAPORE· BEIJING· SHANGHAI· HONG KONG· TAIPEI· CHENNAI Published by World Scientific Publishing Co. Pte. Ltd. 5 Toh Tuck Link, Singapore 596224 USA office: 27 Warren Street, Suite 401-402, Hackensack, NJ 07601 UK office: 57 Shelton Street, Covent Garden, London WC2H 9HE British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library. DOMAIN-THEORETIC FOUNDATIONS OF FUNCTIONAL PROGRAMMING Copyright © 2006 by World Scientific Publishing Co. Pte. Ltd. All rights reserved. This book, or parts thereof, may not be reproduced in any form or by any means, electronic or mechanical, including photocopying, recording or any information storage and retrieval system now known or to be invented, without written permission from the Publisher. For photocopying of material in this volume, please pay a copying fee through the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, USA. In this case permission to photocopy is not required from the publisher. ISBN 981-270-142-7 Printed in Singapore by World Scientific Printers (S) Pte Ltd dedicated to Dana Scott and Gordon Plotkin who invented domain theory and logical relations Contents Preface ix 1. Introduction 1 2. PCF and its Operational Semantics 13 3. The Scott Model of PCF 23 3.1 Basic Domain Theory 25 3.2 Domain Model of PCF 32 3.3 LCF - A Logic of Computable Functionals 34 4. Computational Adequacy 37 5. Milner's Context Lemma 43 6. The Full Abstraction Problem 45 7. Logical Relations 51 8. Some Structural Properties of the Da 57 9. Solutions of Recursive Domain Equations 65 10. Characterisation of Fully Abstract Models 77 vii viii Domain-Theoretic Foundations of Functional Programming 11. Sequential Domains as a Model of PCF 87 12. The Model of PCF in S is Fully Abstract 95 13. Computability in Domains 99 Bibliography 117 Index 119 Preface This little book is the outcome of a course I have given over the last ten years at the Technical University Darmstadt for students of Mathematics and Computer Science. The aim of this course is to provide a solid basis for students who want to write their Masters Thesis in the field of Denotational Semantics or want to start a PhD in this field. For the latter purpose it has been used successfully also at the Univ. of Birmingham (UK) by the students of Martin Escardo. Thus I think this booklet serves well the purpose of filling the gap be­ tween introductory textbooks like e.g. [Winskel 1993] and the many research articles in the area of Denotational Semantics. Intentionally I have concen­ trated on denotational semantics based on Domain Theory and neglected the more recent and flourishing field of Game Semantics (see [Hyland and Ong 2000; Abramsky et.al. 2000]) which in a sense is located in between Operational and Denotational Semantics. The reason for this choice is that on the one hand Game Semantics is covered well in [McCusker 1998] and on the other hand I find domain based semantics mathematically simpler than competing approaches since its nature is more abstract and less combina­ torial. Certainly this preference is somewhat subjective but my excuse is that I think one should write books rather about subjects which one knows quite well than about subjects with which one is less familiar. We develop our subject by studying the properties of the well known functional kernel language PCF introduced by D. Scott in the late 1960ies. The scene is set in Chapters 2 and 3 where we introduce the operational and domain semantics of PCF, respectively. Subsequently we concentrate on studying the relation between operational and domain semantics em­ ploying more and more refined logical relation techniques culminating in the construction of the fully abstract model for PCF in Chapters 11 and ix x Domain- Theoretic Foundations of Functional Programming 12. I think that our construction of the fully abstract model is more elegant and more concise than the accounts which can be found in the literature though, of course, it is heavily based on them. Somewhat off this main thread we show also how to interpret recursive types (Chapter 9) and give a self contained account of computability in Scott domains (Chapter 13) where we prove the classical theorem of [Plotkin 1977] characterizing the computable elements of the Scott model of PCF as those elements defin­ able in PCF extended by two parallel constructs por ("parallel or") and 3 (Plotkin's "continuous existential quantifier") providing an extensional variant of the dove tailing technique known from basic recursion theory. Besides basic techniques like naive set theory, induction and recursion (as covered e.g. by [Winskel 1993]) we assume knowledge of basic cate­ gory theory (as covered by [Barr and Wells 1990] or the first chapters of [MacLane 1998]) from Chapter 9 onwards and knowledge of basic recur­ sion theory only in the final Chapter 13. Except these few prerequisits this little book is essentially self contained. However, the pace of exposition is not very slow and most straightforward verifications—in particular at the beginning—are left to the reader. We recommend the reader to solve the many exercises indicated in the text whenever they show up. Most of them are straightforward and in case they are not we give some hints. I want to express my gratitude to all the colleagues who over the years have helped me a lot by countless discussions, providing preprints etc. Ob­ viously, this little book would have been impossible without the seminal work of Dana Scott and Gordon Plotkin. The many other researchers in the field of domain theoretic semantics who have helped me are too numer­ ous to be listed here. I mention explicitly just Klaus Keimel and Martin Escardo, the former because he was and still is the soul of our little working group on domain theory in Darmstadt, the latter because his successful use of my course notes for his own teaching brought me to think that it might be worthwhile to publish them. Besides for many comments on the text I am grateful to Martin also for helping me a lot with TEXnical matters. I acknowledge the use of Paul Taylor's diagram and prooftree macros which were essential for type setting. Finally I want to thank the staff of IC press for continuous aid and patience with me during the process of preparing this book. I have ex­ perienced collaboration with them as most delightful in all phases of the work. Chapter 1 Introduction Functional programming languages are essentially as old as the more well- known imperative programming languges like FORTRAN, PASCAL, C etc. The oldest functional programming language is LISP which was developed by John McCarthy in the 1950ies, i.e. essentially in parallel with FOR­ TRAN. Whereas imperative or state-oriented languages like FORTRAN were developed mainly for the purpose of numerical computation the in­ tended area of application for functional languages like LISP was (and still is) the algorithmic manipulation of symbolic data like lists, trees etc. The basic constructs of imperative languages are commands which mod­ ify state (e.g. by an assignment x:=E) and conditional iteration of com­ mands (typically by while-loops). Moreover, imperative languages strongly support random access data structures like arrays which are most important in numerical computation. In purely functional languages, however, there is no notion of state or state-changing command. Their basic concepts are • application of a function to an argument • definition of functions either explicitly (e.g. f(x) = x*x+l) or re­ cursively (e.g. f(x) = if x=0 then 1 else x*f(x—l) fi). These examples show that besides application and definition of functions one needs also basic operations on basic data types (like natural numbers or booleans) and a conditional for definition by cases. Moreover, all common functional programming languages like LISP, Scheme, (S)ML, Haskell etc. provide the facility of defining recursive data types by explicitly listing their constructors as e.g. in the following definition of the data type of binary trees tree = empty() | mk_tree(tree, tree) l 2 Domain- Theoretic Foundations of Functional Programming where empty is a O-ary constructor for the empty tree with no sons and mk_tree is a binary constructor taking two trees ti and ti and building a new tree where the left and right sons of its root are t\ and t2, respec­ tively. Thus functional languages support not only the recursive definition of functions but also the recursive definition of data types. The latter has to be considered as a great advantage compared to imperative languages like PASCAL where recursive data types have to be implemented via pointers which is known to be a delicate task and a source of subtle mistakes which are difficult to eliminate. A typical approach to the development of imperative programs is to design a flow chart describing and visualising the dynamic behaviour of the program. Thus, when programming in an imperative language the main task is to organize complex dynamic behaviours, the so-called control flow. In functional programming, however, the dynamic behaviour of pro­ grams need not be specified explicitly. Instead one just has to define the function to be implemented. Of course, in practice these function defini­ tions are fairly hierarchical, i.e. are based on a whole cascade of previously defined auxiliary functions. Then a program (as opposed to a function definition) usually takes the form of an application f(e\,..., e„) which is evaluated by the interpreter1.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages132 Page
-
File Size-