A Declarative Debugger for Haskell

A Declarative Debugger for Haskell

A Declarative Debugger for Haskell Bernard James Pope Submitted in total fulfilment of the requirements of the degree of Doctor of Philosophy December 2006 Department of Computer Science and Software Engineering The University of Melbourne Victoria, Australia Abstract This thesis is about the design and implementation of a debugging tool which helps Haskell programmers understand why their programs do not work as intended. The traditional debugging technique of examining the program execution step-by-step, popular with imperative languages, is less suitable for Haskell because its unorthodox evaluation strategy is difficult to relate to the structure of the original program source code. We build a debugger which focuses on the high-level logical meaning of a program rather than its evaluation order. This style of debugging is called declarative debugging, and it originated in logic programming languages. At the heart of the debugger is a tree which records information about the evaluation of the program in a manner which is easy to relate to the structure of the program. Links between nodes in the tree reflect logical relationships between entities in the source code. An error diagnosis algorithm is applied to the tree in a top-down fashion, searching for causes of bugs. The search is guided by an oracle, who knows how each part of the program should behave. The oracle is normally a human — typically the person who wrote the program — however, much of its behaviour can be encoded in software. An interesting aspect of this work is that the debugger is implemented by means of a program transformation. That is, the program which is to be debugged is trans- formed into a new one, which when evaluated, behaves like the original program but also produces the evaluation tree as a side-effect. The transformed program is augmented with code to perform the error diagnosis on the tree. Running the trans- formed program constitutes the evaluation of the original program plus a debugging iii session. The use of program transformation allows the debugger to take advantage of existing compiler technology — a whole new compiler and runtime environment does not need to be written — which saves much work and enhances portability. The technology described in this thesis is well-tested by an implementation in software. The result is a useful tool, called buddha, which is publicly available and supports all of the Haskell 98 standard. iv Declaration This is to certify that • the thesis comprises only my original work towards the PhD except where indicated in the Preface, • due acknowledgment has been made in the text to all other material used, • the thesis is less than 100,000 words in length, exclusive of tables, maps, bib- liographies, and appendices. v Preface This thesis is based in part on the original work presented in the following four peer reviewed papers: • B. Pope. Declarative debugging with Buddha. In V. Vene and T. Uustalu, editors, Advanced Functional Programming, 5th International School, volume 3622 of Lecture Notes in Computer Science, pages 273–308. Springer-Verlag, 2005. (Invited paper). – The debugging example in Chapter 3 is taken from this paper. – The program transformation algorithm in Chapter 5 is an improved ver- sion of the one discussed in this paper. – The method of observing values for printing in Chapter 6 is based on the technique described in this paper, and also the following paper. • B. Pope and L. Naish. Practical aspects of declarative debugging in Haskell- 98. In Proceedings of the Fifth ACM SIGPLAN Conference on Principles and Practice of Declarative Programming, pages 230–240. ACM Press, 2003. – The re-evaluation scheme and method of debugging of I/O computations in Chapter 7 are based on this paper, though greatly improved in the current presentation. vii • B. Pope and L. Naish. A program transformation for debugging Haskell-98. Australian Computer Science Communications, 25(1):227–236, 2003. – This paper describes an earlier version of the debugging program trans- formation. The treatment of higher-order functions in this paper is the basis of the scheme discussed in Chapter 5 and Chapter 6. • B. Pope and L. Naish. Specialisation of higher-order functions for debugging. In M. Hanus, editor, Proceedings of the International Workshop on Functional and (Constraint) Logic Programming (WFLP 2001), volume 64 of Electronic Notes in Theoretical Computer Science. Elsevier Science Publishers, 2002. – This paper describes an earlier approach to transforming higher-order functions. It is made obsolete by the new transformation described in Chapter 5. We discuss this alternative approach in Chapter 8. Lee Naish contributed to the development of this thesis. He was the secondary author on three of the above-mentioned papers. In addition, the following parts are based extensively on his work: • The definition of buggy nodes in Chapter 3. • The concepts of intended interpretations and inadmissibility in Chapter 4. • The use of quantifiers to handle partial values in derivations in Chapter 4. The following items have not been previously published: • The more flexible definition of evaluation dependency in Chapter 3. • The performance measurements in Chapters 5 and 7. • The improved scheme for piecemeal EDT construction in Chapter 7. viii Acknowledgments Lee Naish, my supervisor, is a pioneer in the field of declarative debugging and I am honoured to work with him for so many years on this topic. Our relationship began in 1997, when I was starting my honours year and keen to work in functional programming. To my great fortune Lee had a project in debugging and was kind enough to let me join in. It was quite clear that a single honours year was not long enough, so I jumped at the chance to continue with a PhD. In my quest for the elusive debugger I have stumbled, taken many wrong paths, and backtracked frequently over well-trodden ground. Such meandering would test even the most patient of souls, yet Lee was happy to let me explore, and always ready to offer sound advice and directions when I needed them. Thank you Lee for supporting me on this long journey, I have enjoyed your friendship and guidance every step of the way. I am also greatly indebted to Harald Søndergaard, my co-supervisor, for leading me to functional programming so many years ago and showing me how stimulating Computer Science can be. I will never forget the day that I became a functional programmer. It was in Harald’s class, he was explaining with his usual enthusiasm the elegance of a line of Haskell code — though he made it seem like it was a line of poetry. From then on I was converted. I must also thank Lee and Harald for proof reading earlier drafts of this thesis. Along the way I have had many functional programming comrades and it would be remiss of me not to give them praise. Foremost is Kevin Glynn, a truly great friend, keen functional programmer, and Wolves supporter. I have many fond mem- ix ories of my time spent with Kevin, in the office, on the soccer pitch (or in the stadium) and also in the pub. I hope that one day we will share the same continent again. I would like to thank all the members of the functional programming group for their support. A PhD can be an isolating experience and it was encouraging to have so many people to lend their ears. Thanks also to the many Mercurians who looked on with interest and provided much inspiration and competition to us lazy Haskellites. For almost all of this degree I lived with Steve Versteeg, a student himself, who showed me how to live life to the fullest extent. We enjoyed many adventures together and helped one another forget the harsh realities of deadlines and progress reports. Though there are many people to thank, none are more deserving of my gratitude than my beloved family. I am fortunate to have such kind and generous parents, Jan and Brian Pope. They are my foundation in life and I am eternally indebted to them for their endless support. I want to thank them for working so hard to allow me to pursue my interests and encouraging me in whatever I choose to do (even when I go about it so slowly). Thanks also to my sister Gabrielle Pope who has stood by me and urged me along in a way that only a big sister can. Outside of the offices and halls of the Computer Science department my life changed in a most remarkable way. I met, and later married, my darling wife Hui Nie Fu. She has been a constant source of love and happiness, and without her help I would not have completed this thesis. I look forward to our life to- gether, especially to exploring the world and visiting her family (my new family) in Selatpanjang. Finally, I would like to thank the Australian Federal Government for supporting this thesis with an Australian Postgraduate Award. x Contents 1 Introduction 1 1.1 Nosilverbullet .............................. 1 1.2 Bugs.................................... 2 1.3 Debugging................................. 3 1.4 DebuggingHaskell ............................ 7 1.5 Declarativedebugging .......................... 9 1.6 Researchproblems ............................ 10 1.6.1 Portability ............................ 10 1.6.2 Scalability............................. 11 1.7 Methodology ............................... 12 1.8 Contributions............................... 13 1.9 Structureofthethesis .......................... 14 2 Haskell 15 2.1 Introduction................................ 15 2.1.1 Outlineofthischapter. 16 2.2 KeyfeaturesofHaskell. .. .. .. .. .. .. .. 16 2.2.1 Syntax............................... 16 2.2.2 Purity............................... 17 2.2.3 Higher-order functions . 18 xi 2.2.4 Static types with polymorphism and overloading . 19 2.2.5 Non-strict evaluation . 20 2.2.6 Implicit memory management . 22 2.3 Dynamicsemantics............................ 23 2.3.1 Termrewriting .........................

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    292 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