Non-Reformist Reform for Haskell Modularity, © October 2019 ABSTRACT
Total Page:16
File Type:pdf, Size:1020Kb
NON-REFORMIST REFORMFOR HASKELL MODULARITY by SCOTT KILPATRICK A dissertation submitted towards the degree Doctor of Engineering (Dr.-Ing.) of the Faculty of Mathematics and Computer Science of Saarland University. Saarbrücken October 2019 date of the colloquium: 15 October 2019 examiners: Prof. Dr. Derek Dreyer (Supervisor) Dr. Andreas Rossberg chair of the examination board: Prof. Dr. Gert Smolka academic assistant: Dr. Andrew Hirsch dean: Prof. Dr. Sebastian Hack Scott Kilpatrick: Non-Reformist Reform for Haskell Modularity, © October 2019 ABSTRACT Module systems like that of Haskell permit only a weak form of modularity in which module implementations depend directly on other implementations and must be processed in depen- dency order. Module systems like that of ML, on the other hand, permit a stronger form of modularity in which explicit interfaces express assumptions about dependencies and each module can be typechecked and reasoned about independently. In this thesis, I present Backpack, a new language for building separately-typecheckable packages on top of a weak module system like Haskell’s. The design of Backpack is the first to bring the rich world of type systems to the practical world of packages via mixin modules. It’s inspired by the MixML module calculus of Rossberg and Dreyer but by choosing practicality over expressivity Backpack both simplifies that semantics and supports a flexible notion of applicative instantiation. Moreover, this design is motivated less by foundational concerns and more by the practical concern of integration into Haskell. The result is a new approach to writing modular software at the scale of packages. The semantics of Backpack is defined via elaboration into sets of Haskell modules and binary interface files, thus showing how Backpack maintains interoperability with Haskell while retrofitting it with interfaces. In my formalization of Backpack I present a novel type system for Haskell modules and I prove a key soundness theorem to validate Backpack’s semantics. ZUSAMMENFASSUNG Modulsysteme wie die in Haskell erlauben nur eine weiche Art der Modularität, in dem Modulimplementierungen direkt von anderen Implementierungen abhängen und in dieser Abhängigkeitsreihenfolge verarbeitet werden müssen. Modulsysteme wie die in ML anderer- seits erlauben eine kräftige Art der Modularität, in dem explizite Schnittstellen Vermutungen über Abhängigkeiten ausdrücken und jeder Modultyp überprüft und unabhängig ergründet werden kann. In dieser Dissertation präsentiere ich Backpack, eine neue Sprache zur Entwicklung separat- typenüberprüfbarer Pakete über einem weichen Modulsystem wie Haskells. Das Design von Backpack überführt erstmalig die reichhaltige Welt der Typsysteme in die praktische Welt der Pakete durch Mixin-Module. Es wird von der MixML-Kalkulation von Rossberg und Dreyer angeregt. Backpack vereinfacht allerdings diese Semantik durch die Auswahl von Anwendbarkeit statt Expressivität und fördert eine flexible Art von geeigneter Applicative- Instantiierung. Zudem wird dieses Design weniger von grundlegenden Anliegen als von dem praktischen Anliegen der Eingliederung in Haskell begründet. Die Semantik von Backpack wird durch die Ausarbeitung in Mengen von Haskell-Modulen und „binary interface files“ definiert, und zeigt so, wie Backpack Interoperabilität mit Has- kell erhält, während Backpack es mit Schnittstellen nachrüstet. In meiner Formalisierung Backpacks präsentiere ich ein neuartiges Typsystem für Haskellmodule und überprüfe einen entscheidenen Korrektheitssatz, um die Semantik von Backpack zu validieren. iii The philosophers have only interpreted the [modularity] in various ways; the point, however, is to change it. — Karl Marx, in the spirit of this work ACKNOWLEDGMENTS What’s a dissertation, anyway? A professional certification? An assemblage of published and unpublished scientific ideas? An extraordinarily labor-intensive memento of frustration, ela- tion, collaboration, and pride? On the occasion of finishing this dissertation, perhaps a few years too late, the richness of my doctoral experience is palpable. With these acknowledgments I hope not only to recognize all those who contributed to it, but also to express that richness for posterity—for friends, family, and prospective PhD students alike. Altogether I’m enormously grateful for the wealth of experience I gained in the Max Planck Society (MPG). Most immediately, that experience comes from my advisor, mentors, collabo- rators, and friends as a PhD student at the Max Planck Institute for Software Systems (MPI- SWS) in Saarbrücken, Germany. Every junior scientist would benefit, as I did, from the expe- rience of living and working abroad in such a respected institution as the MPG. Moreover, I learned a great deal—and hopefully helped change some things for the better—by partic- ipating in the democratic representation of the interests of junior scientists in the scientific workplace, first at MPI-SWS and then as part of the Max Planck PhDnet. We shouldn’t forget that the boundaries of science extend past technical and mathematical matters; it’s also a self- organized profession, with all the material and social concerns that come with the territory of the workplace. As for the people who played notable roles in my scientific development, allow me to enumerate them chronologically. First and foremost, my parents—Nancy and Charlie—always loved and supported me, and encouraged me to pursue math and engineering, even though they had no idea what that meant past 10th grade or so. As an undergraduate at the University of Texas at Austin (UT), my teacher and then mentor Greg Lavender introduced me to functional programming, to the lambda calculus, and to independent study. For introducing me to programming languages research, I’d like to acknowledge Eric Allen, my mentor and supervisor at UT and at Oracle Labs (then Sun Labs). After a rejection from all six PhD programs I had initially applied to, Eric’s tutelage and support helped me turn things around throughout my masters. My colleagues at the Oracle Labs Programming Lan- guages Research Group provided an encouraging and responsive atmosphere where I got my feet wet with research: Eric, Steve Heller, Guy Steele, Sukyoung Ryu, Victor Luchangco, David Chase, and, in particular, my friend and fellow intern (and now mathematician) Justin Hilburn. For introducing me to MPI-SWS, I have my Dumbledore from UT to thank—Lorenzo Alvisi, who told me about the institute and the whole MPG. Working as his TA for grad- uate distributed computing, as a mere masters student, was one of the most challenging and intimidating experiences of my career. His belief in me to take on that challenge, like Greg Lavender’s, had an immense impact on the beginning of my career. As an immigrant scientist himself, Lorenzo also encouraged me to pursue a PhD overseas. (Good advice!) As a periodic visitor to MPI-SWS he continued his Dumbledore role in my life for years. The most critical figure to acknowledge is my PhD advisor at MPI-SWS and friend, Derek Dreyer. His attention to detail, pursuit of simplification, and affable demeanor have certainly left a lasting impression on me. Although my academic career will likely not continue, I have benefited tremendously from the writing and presentation skills I learned from Derek and from his partner Rose Hoberman, the “soft skills” (more generally useful skills!) instructor v at MPI-SWS. Derek also supported me anytime I ruffled feathers in my role as student repre- sentative to the faculty, even when he disagreed; I hope he recognizes the emotional weight of that. He also introduced me to many great films and very often, along with Rose, gave me a good meal. Among the many PhD students, postdocs, and other colleagues at MPI-SWS I enjoyed knowing and working with, I’d like to acknowledge a few in particular, people who left some mark on my scientific career. Beta Ziliani was my “older brother” in Derek’s group, a wonderful friend, a fun colleague to brainstorm with, a Coq expert, and a peerless Grillmeister. Georg Neis, another student of Derek’s, helped with a few proofs but also taught me some Saarlandish culture. Derek’s postdoc Neel Krishnaswami was a constant source of PL wisdom and stimulating conversation. External scientific member—and my academic grandparent— Bob Harper was always a joy to talk to and learn from while visting the institute. From MPI- SWS I’d also like to acknowledge conversations with and other valuable input from Ezgi Çiçek, Allen Clement, Natacha Crooks, Nancy Estrada, Pedro Fonseca, Deepak Garg, Roly Perera, and Aaron Turon. Plenty of others, many friends among them, helped to make the institute a stimulating place to work and study for years. Staff members Mary-Lou Albrecht, Brigitta Hansen, Chris Klein, Claudia Richter, and Carina Schmitt all provided key support during my time there as well. Outside the institute, my friend and would-be PhD sibling Michael Greenberg gave me encouragement, technical feedback, and a personal goalpost for years. The early days of the Backpack project involved multiple visits to Microsoft Research Cam- bridge to work with my collaborators Simon Peyton Jones and Simon Marlow. From Simon PJ I learned a valuable life skill: the confidence to say “I have no idea what’s going on,” a rare skill that has been crucial to my career inside and outside academia. I’m very lucky to have written a paper with him. Also at MSR Cambridge, whiteboard discussions and other chit-chats with fellow module systems expert Claudio Russo were a memorable part of my visits, as was his gift of a pilfered copy of The Commentary on Standard ML. Later on, Edward Yang made perhaps the most significant contribution to the Backpack research project: taking it and running with it in a big way! His enthusiasm and continued shepherding of Backpack helped keep me interested in the work. One additional person deserves acknowledgment for technical contributions to my re- search: Andreas Rossberg. Although his postdoc work with Derek predated my time at MPI-SWS, he spent years as a remote mentor of sorts, someone to whom I could always send hyper-specific module systems ideas and expect a detailed and thoughtful response.