Genericity, extensibility and type : safety in the VISITOR pattern

A software component is, in a general sense, a piece of software that can be safely reused and flexibly adapted by some other piece of software. The safety can be ensured by a type system that guarantees the right usage of the component; the flexibility stems from the fact that components are parametrizable over different aspects affecting their behaviours. Component-oriented programming (COP), a programming style where software would be built out of several independent components, has for a long time eluded the software industry. Several reasons have been raised over time, but one that is consistently pointed out is the inadequacy of existing programming languages for the development of software components. Generic Programming (GP) usually manifests itself as a kind of parametrization. By abstracting from the differences of what would otherwise be separate but otherwise similar specific programs, one can develop a single unified generic program. Instantiating the parameter in various ways retrieves the various specific programs (and ideally some new ones too). Instances of GP include the generics (parametrization by types) mechanism as found in recent versions Java and C# and Datatype-Generic Programming (DGP) (parametrization by shape). Both mechanisms allow novel ways to parametrize programs that can largely increase the flexibility of programs. Software components and GP, and in particular DGP, are clearly related: GP and DGP provide novel ways to parametrize software, while software components benefit from parametrization in order to be flexible. However, DGP and COP have mostly been studied in isolation, with the former being a research topic among some functional programming communities and the latter being mostly studied within the object-oriented communities. In this thesis we will argue for the importance of the parametrization mechanisms provided by GP, and in particular DGP, in COP. We will defend that many design patterns can be captured as software components when using such kinds of parametrization. As evidence for this we will, using DGP techniques, develop a component library for the V pattern that is generic (i.e. can be used on several concrete visitors); extensible (i.e. concrete visitors may be extended); and

[1]  Mira Mezini,et al.  An Overview of CaesarJ , 2006, LNCS Trans. Aspect Oriented Softw. Dev..

[2]  Corrado Böhm,et al.  Automatic Synthesis of Typed Lambda-Programs on Term Algebras , 1985, Theor. Comput. Sci..

[3]  Simon L. Peyton Jones,et al.  Associated type synonyms , 2005, ICFP '05.

[4]  Edsger W. Dijkstra,et al.  The humble programmer , 1972, CACM.

[5]  Simon L. Peyton Jones,et al.  Scrap your boilerplate with class: extensible generic functions , 2005, ICFP '05.

[6]  Simon L. Peyton Jones,et al.  Derivable Type Classes , 2001, Haskell.

[7]  Lennart Augustsson Putting Curry-Howard to work , 2009 .

[8]  Marinus J. Plasmeijer,et al.  A Generic Programming Extension for Clean , 2001, IFL.

[9]  Gilles Roussel,et al.  Reflection-based implementation of Java extensions: the double-dispatch use-case , 2005, SAC '05.

[10]  Jens Palsberg,et al.  The essence of the Visitor pattern , 1998, Proceedings. The Twenty-Second Annual International Computer Software and Applications Conference (Compsac '98) (Cat. No.98CB 36241).

[11]  Johan Nordlander,et al.  Polymorphic subtyping in O'Haskell , 2002, Sci. Comput. Program..

[12]  Ralf Hinze,et al.  Weaving a web , 2001, Journal of Functional Programming.

[13]  Bertrand Meyer,et al.  Componentization: the Visitor example , 2006, Computer.

[14]  Clemens A. Szyperski,et al.  Do We Need Inheritance , 2009 .

[15]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[16]  Martin Odersky,et al.  Extensible algebraic datatypes with defaults , 2001, ICFP '01.

[17]  Martin Odersky,et al.  Scalable component abstractions , 2005, OOPSLA '05.

[18]  Philip Wadler,et al.  A prettier printer , 2002 .

[19]  Ulf Norell,et al.  Polytypic Programming in Haskell , 2003, IFL.

[20]  Simon L. Peyton Jones,et al.  Associated types with class , 2005, POPL '05.

[21]  G. Malcolm,et al.  Data Structures and Program Transformation , 1990, Sci. Comput. Program..

[22]  Conor McBride,et al.  Applicative programming with effects , 2008, J. Funct. Program..

[23]  Jacques Garrigue,et al.  Code reuse through polymorphic variants , 2000 .

[24]  Xavier Leroy,et al.  Manifest types, modules, and separate compilation , 1994, POPL '94.

[25]  Brad J. Cox,et al.  Planning the software industrial revolution , 1990, IEEE Software.

[26]  李幼升,et al.  Ph , 1989 .

[27]  Johan Jeuring,et al.  Generic Views on Data Types , 2006, MPC.

[28]  Christopher Strachey,et al.  Fundamental Concepts in Programming Languages , 2000, High. Order Symb. Comput..

[29]  Richard S. Bird,et al.  Generalised folds for nested datatypes , 1999, Formal Aspects of Computing.

[30]  Wouter Swierstra,et al.  Data types à la carte , 2008, Journal of Functional Programming.

[31]  Clare E. Martin,et al.  Disciplined, efficient, generalised folds for nested datatypes , 2004, Formal Aspects of Computing.

[32]  Ralf Hinze,et al.  Generic Programming, Now! , 2006, SSDGP.

[33]  Bruno C. d. S. Oliveira,et al.  Comparing libraries for generic programming in haskell , 2008, Haskell '08.

[34]  Ralf Hinze,et al.  Generic programming in 3D , 2009, Sci. Comput. Program..

[35]  Maarten M. Fokkinga,et al.  Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire , 1991, FPCA.

[36]  Stephanie Weirich RepLib: a library for derivable type classes , 2006, Haskell '06.

[37]  Jacques Garrigue,et al.  Typing deep pattern-matching in presence of polymorphic variants , 2004 .

[38]  Philip Wadler Monads for Functional Programming , 1995, Advanced Functional Programming.

[39]  簡聰富,et al.  物件導向軟體之架構(Object-Oriented Software Construction)探討 , 1989 .

[40]  Manfred Broy,et al.  What characterizes a (software) component? , 1998, Softw. Concepts Tools.

[41]  Ralf Hinze,et al.  Polytypic Functions Over Nested Datatypes , 1999, Discret. Math. Theor. Comput. Sci..

[42]  Ralf Hinze,et al.  Open data types and open functions , 2006, PPDP '06.

[43]  Bruno C. d. S. Oliveira,et al.  TypeCase: a design pattern for type-indexed functions , 2005, Haskell '05.

[44]  Johan Jeuring,et al.  Polytypic Programming , 1996, Advanced Functional Programming.

[45]  Jeremy Gibbons,et al.  Design patterns as higher-order datatype-generic programs , 2006, WGP '06.

[46]  A. Church An Unsolvable Problem of Elementary Number Theory , 1936 .

[47]  Simon L. Peyton Jones,et al.  Type classes in Haskell , 1994, TOPL.

[48]  James Cheney,et al.  First-Class Phantom Types , 2003 .

[49]  Brian Randell,et al.  Software engineering : report on a conference sponsored by the NATO Science Committee, Garmisch, Germany, 7th to 11th October 1968 , 1969 .

[50]  Gang Chen,et al.  Guarded recursive datatype constructors , 2003, POPL '03.

[51]  Bruno C. d. S. Oliveira,et al.  "Scrap Your Boilerplate" Reloaded , 2006, FLOPS.

[52]  Jeremy Gibbons Patterns in Datatype−Generic Programming , 2003 .

[53]  Andres Löh,et al.  Exploring generic Haskell , 2004 .

[54]  Tim Sheard,et al.  Putting curry-howard to work , 2005, Haskell '05.

[55]  Simon L. Peyton Jones,et al.  Scrap your boilerplate: a practical design pattern for generic programming , 2003, TLDI '03.

[56]  Thomas Kühne,et al.  A functional pattern system for object-oriented design , 1999 .

[57]  Christian Grothoff Walkabout Revisited: The Runabout , 2003, ECOOP.

[58]  Ralf Hinze Generics for the masses , 2004, ICFP '04.

[59]  Richard S. Bird,et al.  Nested Datatypes , 1998, MPC.

[60]  Martin Odersky,et al.  Towards equal rights for higher-kinded types , 2007 .

[61]  Kraig Brockschmidt Inside OLE (2nd ed.) , 1995 .

[62]  Simon L. Peyton Jones,et al.  Simple unification-based type inference for GADTs , 2006, ICFP '06.

[63]  Erik Ernst gbeta - a Language with Virtual Attributes, Block Structure, and Propagating, Dynamic Inheritance , 2000 .

[64]  H Xi,et al.  Dependent Types in Practical Programming. Extended Abstract. , 1999 .

[65]  Andrei Alexandrescu,et al.  Modern C++ Design , 2001 .

[66]  Ralf Hinze,et al.  Fun with phantom types , 2003 .

[67]  James Cheney,et al.  A lightweight implementation of generics and dynamics , 2002, Haskell '02.

[68]  Bruno C. d. S. Oliveira,et al.  The essence of the Iterator pattern , 2006, J. Funct. Program..

[69]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

[70]  Patrik Jansson Functional Polytypic Programming , 2000 .

[71]  Patricia Johann,et al.  Initial Algebra Semantics Is Enough! , 2007, TLCA.

[72]  Hayo Thielecke,et al.  A Type-theoretic Reconstruction of the Visitor Pattern , 2006, MFPS.

[73]  Wouter Joosen,et al.  An object-oriented approach to datatype-generic programming , 2006, WGP '06.

[74]  Ralf Hinze,et al.  "Scrap Your Boilerplate" Revolutions , 2006, MPC.

[75]  Martin Odersky,et al.  Independently Extensible Solutions to the Expression Problem , 2004 .

[76]  Mads Torgersen The expression problem revisited: Four new solutions using generics , 2004 .

[77]  Mark Lillibridge,et al.  A type-theoretic approach to higher-order modules with sharing , 1994, POPL '94.

[78]  Clemens A. Szyperski,et al.  Why objects are not enough , 1998 .

[79]  Joseph A. Goguen,et al.  Initial Algebra Semantics , 1974, SWAT.

[80]  Bruno C. d. S. Oliveira,et al.  Extensible and modular generics for the masses , 2006, Trends in Functional Programming.

[81]  Alan Snyder Encapsulation and inheritance in object-oriented programming languages , 1986, OOPSLA 1986.

[82]  Gérard P. Huet,et al.  The Zipper , 1997, Journal of Functional Programming.

[83]  Michel Parigot Recursive Programming with Proofs , 1992, Theor. Comput. Sci..

[84]  Andrew C. Myers,et al.  Scalable extensibility via nested inheritance , 2004, OOPSLA.

[85]  Aarne Ranta,et al.  A pattern for almost compositional functions , 2006, ICFP '06.

[86]  Simon L. Peyton Jones,et al.  Scrap more boilerplate: reflection, zips, and generalised casts , 2004, ICFP '04.

[87]  Simon L. Peyton Jones,et al.  Scrap Your Boilerplate , 2003, APLAS.

[88]  Roland Carl Backhouse,et al.  Polynomial Relators (Extended Abstract) , 1991, AMAST.

[89]  Ralf Hinze,et al.  Polytypic values possess polykinded types , 2000, Sci. Comput. Program..

[90]  Philip Wadler,et al.  Theorems for free! , 1989, FPCA.

[91]  Martin Odersky,et al.  A Core Calculus for Scala Type Checking , 2006, MFCS.

[92]  Pieter Koopman,et al.  Data Types and Pattern Matching by Function Application , 2005 .

[93]  Richard S. Bird,et al.  Generic functional programming with types and relations , 1996, Journal of Functional Programming.

[94]  Oscar Nierstrasz,et al.  Traits: Composable Units of Behaviour , 2002, ECOOP.

[95]  Roland Carl Backhouse,et al.  Elements of a Relational Theory of Datatypes , 1993, Formal Program Development.