ABSTRACT
The 'Scrap your boilerplate' approach to generic programming allows the programmer to write generic functions that can traverse arbitrary data structures, and yet have type-specific cases. However, the original approach required all the type-specific cases to be supplied at once, when the recursive knot of generic function definition is tied. Hence, generic functions were closed. In contrast, Haskell's type classes support open, or extensible, functions that can be extended with new type-specific cases as new data types are defined. In this paper, we extend the 'Scrap your boilerplate' approach to support this open style. On the way, we demonstrate the desirability of abstraction over type classes, and the usefulness of recursive dictionarie.
- Michael Brandt and Fritz Henglein. Coinductive axiomatization of recursive type equality and subtyping. In Proc 3rd International Conference on Typed Lambda Calculi and Appliactions (TLCA'97), Nancy, France, volume 1210 of Lecture Notes in Computer Science, pages 63--81. Springer Verlag, 1997.]] Google Scholar
- A.I. Baars and S.D. Swierstra. Typing dynamic typing. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2002), pages 157--166. ACM Press, 2002.]] Google ScholarDigital Library
- L Cardelli. Amber. In G Cousineau, PL Curien, and B Robinet, editors, Combinators and functional programming languages. LNCS 242, Springer Verlag, 1986.]] Google ScholarDigital Library
- Koen Claessen and John Hughes. QuickCheck: a lightweight tool for random testing of Haskell programs. In ACM SIGPLAN International Conference on Functional Programming (ICFP'00), pages 268--279, Montreal, September 2000. ACM.]] Google ScholarDigital Library
- J. Cheney and R. Hinze. A lightweight implementation of generics and dynamics. In Proceedings of the ACM SIGPLAN Workshop on Haskell, pages 90--104. ACM Press, 2002.]] Google ScholarDigital Library
- Koen Claessen and John Hughes. Testing monadic code with QuickCheck. In Manuel Chakravarty, editor, Proceedings ofthe 2002 Haskell Workshop, Pittsburgh, October 2002.]] Google ScholarDigital Library
- Dave Clarke and Andres Löh. Generic Haskell, Specifically. In Proceedings of the IFIP TC2/WG2.1 Working Conference on Generic Programming, pages 21--47. Kluwer, B.V., 2003.]] Google ScholarDigital Library
- Simon D. Foster. "HAIFA: The Haskell Application Interoperation Framework Architecture"; web site, 2004--2005. http://www.repton-world.org.uk/mediawiki/index.php/HAIFA_Wiki.]]Google Scholar
- Ralf Hinze. Generics for the masses. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2004), pages 236--243. ACM Press, 2004.]] Google ScholarDigital Library
- Robert Harper and Greg Morrisett. Compiling polymorphism using intensional type analysis. In Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles Of Programming Languages (POPL 1995), pages 130--141. ACM Press, 1995.]] Google ScholarDigital Library
- Ralf Hinze and Simon Peyton Jones. Derivable type classes. In Graham Hutton, editor, Proceedings of the 2000 Haskell Workshop, Montreal, number NOTTCS-TR-00-1 in Technical Reports, September 2000.]]Google Scholar
- RJM Hughes. Restricted data types in haskell. In Erik Meijer, editor, Proceedings of the 1999 Haskell Workshop, number UU-CS-1999-28 in Technical Reports, 1999. ftp://ftp.cs.uu.nl/pub/RUU/CS/techreps/CS-1999/1999-28.pdf.]]Google Scholar
- Andres Löh, Dave Clarke, and Johan Jeuring. Dependencystyle Generic Haskell. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2003), pages 141--152. ACM Press, August 25-29 2003.]] Google ScholarDigital Library
- Jeffrey R. Lewis, John Launchbury, Erik Meijer, and Mark B. Shields. Implicit parameters: dynamic scoping with static types. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles Of Programming Languages (POPL 2000), pages 108--118. ACM Press, 2000.]] Google ScholarDigital Library
- Ralf Lämmel and Simon Peyton Jones. Scrap your boilerplate: a practical approach to generic programming. In ACM SIGPLAN International Workshop on Types in Language Design and Implementation (TLDI'03), pages 26--37, New Orleans, January 2003. ACM.]] Google ScholarDigital Library
- Ralf Lämmel and Simon Peyton Jones. Scrap more boilerplate: reflection, zips, and generalised casts. In ACM SIGPLAN International Conference on Functional Programming (ICFP'04), pages 244--255, Snowbird, Utah, September 2004. ACM.]] Google ScholarDigital Library
- K Zhuo Ming Lu and M Sulzmann. An implementation of subtyping among regular expression types. In Proc Asian Programming Languages Symposium (APLAS'04), volume 3302 of Lecture Notes in Computer Science, pages 57--73. Springer Verlag, 2004.]]Google ScholarCross Ref
- Benjamin Pierce. Types and programming languages. MIT Press, 2002.]] Google ScholarDigital Library
- T Sheard and SL Peyton Jones. Template meta-programming for Haskell. In Manuel Chakravarty, editor, Proceedings of the 2002 Haskell Workshop, Pittsburgh, October 2002.]] Google ScholarDigital Library
- Konstantinos F. Sagonas, Terrance Swift, and David Scott Warren. An abstract machine for efficiently computing queries to well-founded models. J. Log. Program., 45(1--3):1--41, 2000.]]Google Scholar
- Dimitrios Vytiniotis, Geoffrey Washburn, and Stephanie Weirich. An Open and Shut Typecase. In Proceedings of the ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI 2005). ACM Press, January 2005.]] Google ScholarDigital Library
- PL Wadler and S Blott. How to make ad-hoc polymorphism less ad hoc. In Proc 16th ACM Symposium on Principles of Programming Languages, Austin, Texas. ACM, January 1989.]] Google ScholarDigital Library
- S. Weirich. Type-safe cast: (functional pearl). In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2000), pages 58--67. ACM Press, 2000.]] Google ScholarDigital Library
Index Terms
- Scrap your boilerplate with class: extensible generic functions
Recommendations
Scrap more boilerplate: reflection, zips, and generalised casts
ICFP '04: Proceedings of the ninth ACM SIGPLAN international conference on Functional programmingWriting boilerplate code is a royal pain. Generic programming promises to alleviate this pain by allowing the programmer to write a generic "recipe" for boilerplate code, and use that recipe in many places. In earlier work we introduced the "Scrap your ...
Scrap your boilerplate: a practical design pattern for generic programming
TLDI '03: Proceedings of the 2003 ACM SIGPLAN international workshop on Types in languages design and implementationWe describe a design pattern for writing programs that traverse data structures built from rich mutually-recursive data types. Such programs often have a great deal of "boilerplate" code that simply walks the structure, hiding a small amount of "real" ...
Scrap your boilerplate with class: extensible generic functions
Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingThe 'Scrap your boilerplate' approach to generic programming allows the programmer to write generic functions that can traverse arbitrary data structures, and yet have type-specific cases. However, the original approach required all the type-specific ...
Comments