
A dissertation for the Ph.D. degree in Computing Science Reactive Objects and Functional Programming Johan Nordlander Department of Computing Science Chalmers University of Technology SE-412 96 G¨oteborg, Sweden G¨oteborg, May 1999 A dissertation for the Ph.D. Degree in Computing Science at Chalmers University of Technology Department of Computing Science Chalmers University of Technology SE-412 96 G¨oteborg, Sweden Reactive Objects and Functional Programming Johan Nordlander G¨oteborg 1999 ISBN 91-7197-823-2 Doktorsavhandlingar vid Chalmers Tekniska H¨ogskola Ny serie 1521 ISSN 0346-718X Abstract The construction of robust distributed and interactive software is still a chal- lenging task, despite the recent popularity-increase for languages that take ad- vanced programming concepts into the mainstream. Several problematic areas can be identified: most languages require the reactivity of a system to be man- ually upheld by careful avoidance of blocking operations; mathematical values often need to be encoded in terms of stateful objects or vice versa; concurrency is particularly tricky in conjunction with encapsulated software components; and static type safety is often compromised because of the lack of simultaneous support for both subtyping and polymorphism. This thesis presents a programming language, O'Haskell, that has been con- sciously designed with these considerations in mind. O'Haskell is defined by conservatively extending the purely functional language Haskell with the fol- lowing features: • A central structuring mechanism based on reactive objects, which unify the notions of objects and concurrent processes. Reactive objects are asynchronous, state-encapsulating servers whose purpose is to react to input messages; they cannot actively block execution or selectively filter their sources of input. • A monadic layer of object-based computational effects, which clearly sep- arates stateful objects from stateless values. Apart from higher-order functions and recursive data structures, the latter notion also includes first-class commands, object templates, and methods. • A safe, polymorphic type system with declared record and datatype sub- typing, supported by a powerful partial type inference algorithm. It is claimed that these features make O'Haskell especially well-adapted for the task of modern software construction. The thesis presents O'Haskell from both a practical and a theoretical per- spective. The practical contributions are a full implementation of the language, a number of non-trivial programming examples that illustrate the merits of re- active objects in a realistic context, and several reusable programming methods for such applications as graphical user interfaces, embedded controllers, and network protocols. The theoretical results serve to substantiate the informal claim made regarding usability, and include a provably sound polymorphic sub- typing system, soundness and partial completeness for the inference algorithm, a formal dynamic semantics, and a result that characterizes the conservative extension of a purely functional language with state and concurrency. Keywords: language design, functional programming, concurrency, reactive objects, polymorphic subtyping. Creativity is allowing yourself to make mistakes. Art is to know which ones to keep. | Scott Adams, creator of Dilbert. Acknowledgements Ten years ago Bj¨orn von Sydow, even then a renowned lecturer, and I, his under- graduate student, were having a discussion concerning the ideal programming language during a lunch-break at the Lule˚a Technical University. Although the discussion was conducted in rather vague terms, I still remember getting a very clear picture of what this ideal language should look like. When I now find myself in a position where I can sum up the many years of programming lan- guage research that have ultimately led to a finished thesis, I can only conclude that the result was there all the time! This was the language we were talking about, and it only makes me proud to give credit where credit is due | to my supervisor Bj¨orn von Sydow, who put me on the right track long before I knew I wanted to be a research student, and who has kept me on that track ever since. Thanks, Bj¨orn, for being such an enormous source of inspiration, for believing in me, and for letting me make the right mistakes! The Department of Computing Science at Chalmers has provided a very rich and stimulating research environment, and I would like to express my gratitude to its skilled administrative staff, and to all past and present colleagues with whom I have had so many joyful and educative encounters. I am particularly indebted to two very special friends and colleagues. Mag- nus Carlsson showed an early interest in my work (despite my ranting!), and soon became involved in it himself. Chapter 6 is based on work jointly per- formed with him. Magnus has also provided me with numerous comments on drafts of this thesis. Thomas Hallgren and I have had long discussions on type systems and almost every other subject as well, and he also provided the first full implementation of my subtype inference algorithm. Both Magnus and Thomas have moreover been an important part of my social life in G¨oteborg, and the only sensible way of acknowledging their influence on the making of this thesis is by saying: thanks for everything, brothers! It has been a pleasure! Thanks are also due to my supervision committee | Bengt Nordstr¨om, Dave Sands, and Thomas Johnson | for giving me useful comments on an earlier draft of the thesis and the work that has preceded it. The dissertation has also benefited from stimulating discussions with Lars Pareto, Lennart Augustsson, Simon Peyton Jones, Norman Ramsey, Rogardt Heldal, and Dan Synek, among others. I am moreover indebted to Fritz Henglein for patiently introducing me to the field of polymorphic subtyping, and to Philippas Tsigas and Marina Papatriantafilou for helping me sorting out the mysteries of self-stabilization. The commuting life I have been living during this period would not have been possible without the support of all good friends in G¨oteborg who have opened up their homes for me. To Johanna & Sven, Gunnel & Johan, Rauni & Pontus, Bj¨orn & Vero, Patrik & Lina, Janne & Camilla: my hearty thanks for the hospitality and the good company, and I hope you all feel that my family and I are always keeping our door open for you as well. Vivi-Anne Lundstr¨om's skilled eyes have helped me identify many weak spots in my English presentation, which I gratefully acknowledge. Vivi-Anne and Jack have also been a dependable source of encouragement over the years, as well as providers of invaluable help in numerous practical matters (especially during this last hectic period), and for that I am particularly grateful. A very special place in my heart is reserved for Siv Lundstr¨om and Owe Wikstr¨om, whom I count as my best friends, in the true meaning of the word. This work would not have been thinkable without their care and support, and I dedicate my thesis to them with pride. Finally, my most intimate thank you goes to Eva, my love and fellow-traveller in life. Much has changed since that distant day I left for Lule˚a to study and live in a caravan on a camp closed for the winter, but her love and unbroken faith in my capabilities has been a constant factor in my life. Now we share our home with three wonderful children, and to them I just want to say now that the \fairy-tale book" is finally written: Agnes, Charlott och Oskar | nu ska vi leka! This dissertation is partly based on previously published material. Chapter 5 is an extended version of [Nor98], and chapter 6 is based on the work reported in [NC97]. Some original thoughts underlying the thesis can also be found in [Nor95], although the technical material contained in that report should be considered superseded by [NC97] and the present work. Contents 1 Introduction 1 1.1 Background . 1 1.2 Thesis . 4 1.3 Reactive objects . 5 1.3.1 Object modeling . 5 1.3.2 Preserving reactivity . 7 1.3.3 Reactivity in interfaces . 8 1.3.4 Preserving message ordering . 9 1.4 Values vs. Objects . 10 1.4.1 Values in object-oriented languages . 10 1.4.2 Functional programming . 11 1.4.3 A monadic approach to objects . 12 1.5 Subtyping and polymorphism . 13 1.5.1 Subtyping and type inference . 15 1.5.2 Name inequivalence . 16 1.6 Related work . 16 1.6.1 Concurrency in functional languages . 16 1.6.2 Concurrent object-oriented languages . 18 1.6.3 Reactivity . 19 1.6.4 Polymorphic subtyping . 21 1.6.5 Name inequivalence . 22 1.7 Contributions . 23 1.8 Outline of the thesis . 24 2 Survey of O'Haskell 27 2.1 Haskell . 28 2.2 Records . 33 2.3 Subtyping . 35 2.3.1 Polymorphic subtype axioms . 36 2.3.2 Depth subtyping . 37 2.3.3 Restrictions on subtype axioms . 38 2.4 Automatic type inference . 39 2.5 Reactive objects . 42 2.5.1 Templates and methods . 42 vii viii CONTENTS 2.5.2 Procedures and commands . 43 2.5.3 A word about overloading . 44 2.5.4 Assignable local state . 45 2.5.5 The O monad . 46 2.5.6 Self . 47 2.5.7 Expressions vs. commands . 47 2.5.8 Subtyping in the O monad . 49 2.5.9 The main procedure . 50 2.5.10 Concurrency . 50 2.5.11 Reactivity . 51 2.6 Additional extensions . 52 2.6.1 Extended do-syntax . 52 2.6.2 Array updates . 53 2.6.3 Record stuffing . 54 2.7 What about inheritance? . 54 3 Examples 57 3.1 An interactive drawing program . 57 3.2 An AGV controller . 62 3.3 Sieve of Eratosthenes .
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages208 Page
-
File Size-