Abstract
Generic programming allows you to write a function once, and use it many times at different types. Traditionally, generic functions are defined by induction on the structure of types. “Scrap your boilerplate” (SYB) is a radically different approach that dispatches on the structure of values. In previous work, we have shown how to reconcile both approaches using the concept of generic views: many generic functions can be based either on the classical sum-of-products view or on the view that underlies SYB, the so-called ‘spine’ view. One distinct advantage of the spine view is its generality: it is applicable to a large class of data types, including generalised algebraic data types. Its main weakness roots in the value-orientation: one can only define generic functions that consume data (show) but not ones that produce data (read). Furthermore, functions that abstract over type constructors (map, reduce) are out of reach. In this paper, we show how to overcome both limitations. The main technical contributions are the ‘type spine’ view and the ‘lifted spine’ view.
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
Jansson, P., Jeuring, J.: PolyP—a polytypic programming language extension. In: Conference Record 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 1997), Paris, France, pp. 470–482. ACM Press, New York (1997)
Hinze, R., Jeuring, J.: Generic haskell: Practice and theory. In: Backhouse, R., Gibbons, J. (eds.) Generic Programming. LNCS, vol. 2793, pp. 1–56. Springer, Heidelberg (2003)
Peyton Jones, S., Lämmel, R.: Scrap your boilerplate: A practical approach to generic programming. In: Proceedings of the ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI 2003), New Orleans, pp. 26–37 (2003)
Hall, C.V., Hammond, K., Peyton Jones, S.L., Wadler, P.L.: Type classes in Haskell. ACM Transactions on Programming Languages and Systems 18(2), 109–138 (1996)
Lämmel, R., Peyton Jones, S.: Scrap your boilerplate with class: extensible generic functions. In: Pierce, B. (ed.) Proceedings of the 2005 International Conference on Functional Programming, Tallinn, Estonia, September 26-28 (2005)
Weirich, S.: Type-safe cast: Functional pearl. In: Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2000), ACM SIGPLAN Notices, vol. 35(9), pp. 58–67. ACM Press, New York (2000)
Crary, K., Weirich, S., Morrisett, G.: Intensional polymorphism in type-erasure semantics. In: Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 1998) ACM SIGPLAN Notices, Baltimore, MD, vol. 34(1), pp. 301–312. ACM Press, New York (1999)
Cheney, J., Hinze, R.: A lightweight implementation of generics and dynamics. In: Chakravarty, M.M. (ed.) Proceedings of the 2002 ACM SIGPLAN Haskell Workshop, pp. 90–104. ACM Press, New York (2002)
Hinze, R.: A new approach to generic functional programming. In: Reps, T.W. (ed.) Proceedings of the 27th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2000), Boston, Massachusetts, January 19-21, pp. 119–132 (2000)
Hinze, R.: Generics for the masses. In: Fisher, K. (ed.) Proceedings of the 2004 International Conference on Functional Programming, Snowbird, Utah, September 19-22, 2004, pp. 236–243. ACM Press, New York (2004)
Hinze, R., Löh, A., Oliveira, B.C.: Scrap Your Boilerplate reloaded. In: Hagiya, M., Wadler, P. (eds.) FLOPS 2006. LNCS, vol. 3945. Springer, Heidelberg (2006)
Xi, H., Chen, C., Chen, G.: Guarded recursive datatype constructors. In: Proceedings of the ACM SIGPLAN-SIGACT symposium on Principles of Programming Languages (POPL 2003), pp. 224–235. ACM Press, New York (2003)
Peyton Jones, S., Washburn, G., Weirich, S.: Wobbly types: Type inference for generalised algebraic data types. Technical Report MS-CIS-05-26, University of Pennsylvania (2004)
Wadler, P.: Theorems for free! In: The Fourth International Conference on Functional Programming Languages and Computer Architecture (FPCA 1989), London, UK, pp. 347–359. Addison-Wesley Publishing Company, Reading (1989)
Hughes, R.J.M.: A novel representation of lists and its application to the function “reverse”. Information Processing Letters 22(3), 141–144 (1986)
Bird, R., Meertens, L.: Nested datatypes. In: Jeuring, J. (ed.) MPC 1998. LNCS, vol. 1422, pp. 52–67. Springer, Heidelberg (1998)
Hinze, R.: Functional Pearl: Perfect trees and bit-reversal permutations. Journal of Functional Programming 10(3), 305–317 (2000)
Hutton, G.: Higher-order functions for parsing. Journal of Functional Programming 2(3), 323–343 (1992)
Peyton Jones, S.: Haskell 1998 Language and Libraries. Cambridge University Press, Cambridge (2003)
Jones, M.P.: A system of constructor classes: Overloading and implicit higher-order polymorphism. Journal of Functional Programming 5(1), 1–35 (1995)
Hinze, R.: Fun with phantom types. In: Gibbons, J., de Moor, O. (eds.) The Fun of Programming, pp. 245–262. Palgrave Macmillan, Basingstoke (2003)
Lämmel, R., Peyton Jones, S.: Scrap more boilerplate: reflection, zips, and generalised casts. In: Fisher, K. (ed.) Proceedings of the 2004 International Conference on Functional Programming, Snowbird, Utah, September 19-22, 2004, pp. 244–255 (2004)
Backhouse, R., Jansson, P., Jeuring, J., Meertens, L.: Generic Programming — An Introduction. In: Swierstra, S.D., Henriques, P.R., Oliveira, J.N. (eds.) AFP 1998. LNCS, vol. 1608, pp. 28–115. Springer, Heidelberg (1999)
Hinze, R., Jeuring, J.: Generic haskell: Applications. In: Backhouse, R., Gibbons, J. (eds.) Generic Programming. LNCS, vol. 2793, pp. 57–96. Springer, Heidelberg (2003)
Harper, R., Morrisett, G.: Compiling polymorphism using intensional type analysis. In: 22nd Symposium on Principles of Programming Languages, POPL 1995, pp. 130–141 (1995)
Crary, K., Weirich, S.: Flexible type analysis. In: Proceedings ICFP 1999: International Conference on Functional Programming, pp. 233–248. ACM Press, New York (1999)
Trifonov, V., Saha, B., Shao, Z.: Fully reflexive intensional type analysis. In: Proceedings ICFP 2000: International Conference on Functional Programming, pp. 82–93. ACM Press, New York (2000)
Weirich, S.: Encoding intensional type analysis. In: Sands, D. (ed.) ESOP 2001. LNCS, vol. 2028, pp. 92–106. Springer, Heidelberg (2001)
Norell, U., Jansson, P.: Polytypic programming in haskell. In: Trinder, P., Michaelson, G.J., Peña, R. (eds.) IFL 2003. LNCS, vol. 3145, pp. 168–184. Springer, Heidelberg (2004)
Oliveira, B.C., Gibbons, J.: Typecase: A design pattern for type-indexed functions. In: Leijen, D. (ed.) Proceedings of the 2005 ACM SIGPLAN workshop on Haskell, Tallinn, Estonia, pp. 98–109 (2005)
Hinze, R., Peyton Jones, S.: Derivable type classes. In: Hutton, G. (ed.) Proceedings of the 2000 ACM SIGPLAN Haskell Workshop. Electronic Notes in Theoretical Computer Science, vol. 41.1. Elsevier Science, Amsterdam (2001); The preliminary proceedings appeared as a University of Nottingham technical report
Alimarine, A., Plasmeijer, R.: A generic programming extension for Clean. In: Arts, T., Mohnen, M. (eds.) Proceedings of the 13th International workshop on the Implementation of Functional Languages, IFL 2001, Älvsjö, Sweden, pp. 257–278 (2001)
Hinze, R.: Polytypic values possess polykinded types. Science of Computer Programming 43, 129–159 (2002)
Löh, A.: Exploring Generic Haskell. PhD thesis, Utrecht University (2004)
Löh, A., Jeuring, J.: The Generic Haskell user’s guide, version 1.42 - Coral release. Technical Report UU-CS-2005-004, Universiteit Utrecht (2005)
Hinze, R., Löh, A., Oliveira, B.C.: “Scrap Your Boilerplate” reloaded. Technical Report IAI-TR-2006-2, Institut für Informatik III, Universität Bonn (2006)
Jones, M.P.: Type classes with functional dependencies. In: Smolka, G. (ed.) ESOP 2000. LNCS, vol. 1782, pp. 230–244. Springer, Heidelberg (2000)
Hinze, R., Jeuring, J., Löh, A.: Type-indexed data types. Science of Computer Programming 51, 117–151 (2004)
Clarke, D., Löh, A.: Generic Haskell, specifically. In: Gibbons, J., Jeuring, J. (eds.) Proceedings of the IFIP TC2 Working Conference on Generic Programming, Schloss Dagstuhl, pp. 21–48. Kluwer Academic Publishers, Dordrecht (2002)
Visser, E.: Language independent traversals for program transformation. In: Jeuring, J. (ed.) Proceedings of the 2nd Workshop on Generic Programming, Ponte de Lima, Portugal, pp. 86–104 (2000); The proceedings appeared as a technical report of Universiteit Utrecht, UU-CS-2000-19
Hinze, R., Löh, A.: Open data types and open functions. Technical Report IAI-TR-2006-3, Institut für Informatik III, Universität Bonn (2006)
Reig, F.: Generic proofs for combinator-based generic programs. In: Loidl, H.W. (ed.) Trends in Functional Programming, Intellect, vol. 5 (2006)
Braun, W., Rem, M.: A logarithmic implementation of flexible arrays. Memorandum MR83/4, Eindhoven University of Technology (1983)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2006 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Hinze, R., Löh, A. (2006). “Scrap Your Boilerplate” Revolutions. In: Uustalu, T. (eds) Mathematics of Program Construction. MPC 2006. Lecture Notes in Computer Science, vol 4014. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11783596_13
Download citation
DOI: https://doi.org/10.1007/11783596_13
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-35631-8
Online ISBN: 978-3-540-35632-5
eBook Packages: Computer ScienceComputer Science (R0)