Abstract
Generic programming aims to increase the flexibility of programming languages, by expanding the possibilities for parametrization — ideally, without also expanding the possibilities for uncaught errors. The term means different things to different people: parametric polymorphism, data abstraction, meta-programming, and so on. We use it to mean polytypism, that is, parametrization by the shape of data structures rather than their contents. To avoid confusion with other uses, we have coined the qualified term datatype-generic programming for this purpose. In these lecture notes, we expand on the definition of datatype-generic programming, and present some examples of datatype-generic programs. We also explore the connection with design patterns in object-oriented programming; in particular, we argue that certain design patterns are just higher-order datatype-generic programs.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Reference manual for the Ada programming language. American National Standards Institute, Inc., ANSI/MIL-STD-1815A-1983 (1983)
Aigner, M., Ziegler, G.M.: Proofs from The Book, 3rd edn. Springer, Heidelberg (2004)
Alexandrescu, A.: Modern C++ Design. Addison-Wesley, Reading (2001)
Austern, M.: Generic Programming and the STL: Using and Extending the C++ Standard Template Library. Addison-Wesley, Reading (1998)
Backhouse, R.C., Carré, B.A.: Regular algebra applied to path-finding problems. Journal of the Institute of Mathematics and Applications 15, 161–186 (1975)
Backhouse, R., Hoogendijk, P.: FIP TC2/WG2.1 State-of-the-Art Report on Formal Program Development. In: Möller, B., Schuman, S., Partsch, H. (eds.) Formal Program Development. LNCS, vol. 755, pp. 7–42. Springer, Heidelberg (1993)
Backhouse, R.C., Jansson, P., Jeuring, J., Meertens, L.G.L.T.: Generic programming: An introduction. In: Swierstra, S.D., Oliveira, J.N. (eds.) AFP 1998. LNCS, vol. 1608, pp. 28–115. Springer, Heidelberg (1999)
Bidoit, M., Mosses, P.: User Manual. In: Bidoit, M., Mosses, P.D. (eds.) CASL User Manual. LNCS, vol. 2900, Springer, Heidelberg (2004)
Bird, R., de Moor, O.: The Algebra of Programming. Prentice-Hall, Englewood Cliffs (1996)
Bird, R., de Moor, O., Hoogendijk, P.: Generic functional programming with types and relations. Journal of Functional Programming 6(1), 1–28 (1996)
Bird, R.S.: Using circular programs to eliminate multiple traversals of data. Acta Informatica 21, 239–250 (1984)
Bird, R.S.: Lectures on constructive functional programming. In: Broy, M. (ed.) Constructive Methods in Computer Science, pp. 151–218. Springer, Heidelberg Also available as Technical Monograph PRG-69, from the Programming Research Group, Oxford University (1988)
Bracha, G., Cohen, N., Kemper, C., Marx, S., Odersky, M., Panitz, S.-E., Stoutamire, D., Thorup, K., Wadler, P.: Add generic types to the Java programming language (April 2001), JSR 14 http://www.jcp.org /en/jsr/detail?id=014
Bronstein, M., Burge, W., Daly, T., Davenport, J., Dewar, M., Dunstan, M., Fortenbacher, A., Gianni, P., Grabmeier, J., Guidry, J., Jenks, R., Lambe, L., Monagan, M., Morrison, S., Sit, W., Steinbach, J., Sutor, R., Trager, B., Watt, S., Wen, J., Williamson, C.: The Thirty-Year Horizon (2003), http://wiki.axiom-developer.org /Mirrors?go=/public/book2.pdf
Buchlovsky, P., Thielecke, H.: A type-theoretic reconstruction of the Visitor pattern. In: 21st Conference on Mathematical Foundations of Programming Semantics. Electronic Notes in Theoretical Computer Science, vol. 155 (2005)
Cardelli, L., Wegner, P.: On understanding types, data abstraction and polymorphism. ACM Computing Surveys 17(4), 471–522 (1985)
Cheney, J., Hinze, R.: A lightweight implementation of generics and dynamics. In: Haskell Workshop, pp. 90–104 (2002)
Claessen, K., Hughes, J.: Specification based testing with QuickCheck. In: Gibbons, de Moor[45], pp. 17–40
Clarke, D., Löh, A., Haskell, G.: specifically. In: Gibbons, Jeuring [47], pp. 21–47
Mosses, P.D. (ed.): CASL Reference Manual. LNCS, vol. 2960. Springer, Heidelberg (2004)
Cormen, T.H., Leiserson, C.E., Rivest, R.L.: Introduction to Algorithms. MIT Press, Cambridge (1990)
Czarnecki, K., Eisenecker, U.: Generative Programming: Methods, Tools and Applications. Addison-Wesley, Reading (2000)
Damas, L., Milner, R.: Principal type schemes for functional programs. In: Principles of Programming Languages, pp. 207–212 (1982)
Day, N., Launchbury, J., Lewis, J.: Logical abstractions in haskell. In: Haskell Workshop. Utrecht University Department of Computer Science, Technical Report UU-CS-1999-28 (October 1999)
Dehnert, J., Stepanov, A.: Fundamentals of generic programming. In: Jazayeri, M., Musser, D.R., Loos, R.G.K. (eds.) Generic Programming. LNCS, vol. 1766, pp. 1–11. Springer, Heidelberg (2000)
dos Santos Oliveira, B.C., Gibbons, J.: TypeCase: A design pattern for type-indexed functions. In: Leijen, D. (ed.) Haskell Workshop (2005)
Edmonds, J.: Matroids and the Greedy Algorithm. Mathematical Programming 1, 125–136 (1971)
Ehrig, H., Mahr, B.: Fundamentals of Algebraic Specification 1: Equations and Initial Semantics. Springer, Heidelberg (1985)
Ehrig, H., Mahr, B.: Fundamentals of Algebraic Specification 2: Module Specifications and Constraints. Springer, Heidelberg (1990)
Fokkinga, M.: Monadic maps and folds for arbitrary datatypes. Department INF, Universiteit Twente (June 1994)
Fokkinga, M.M.: Tupling and mutumorphisms. The Squiggolist 1(4), 81–82 (1990)
Fokkinga, M.M., Meijer, E.: Program calculation properties of continuous algebras. Technical Report CS-R9104, CWI, Amsterdam (January 1991)
Forman, I.R., Danforth, S.: Putting Metaclasses to Work. Addison-Wesley, Reading (1999)
Gamma, E., Beck, K.: JUnit: Testing resources for extreme programming (2000), http://www.junit.org/
Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading (1995)
Ghani, N., Uustalu, T., Vene, V.: Build, augment and destroy, universally. In: Chin, W.-N. (ed.) APLAS 2004. LNCS, vol. 3302, Springer, Heidelberg (2004)
Gibbons, J.: Calculating functional programs. In: Blackhouse, R., Crole, R.L., Gibbons, J. (eds.) Algebraic and Coalgebraic Methods in the Mathematics of Program Construction. LNCS, vol. 2297, pp. 148–203. Springer, Heidelberg (2002)
Gibbons, J.: Origami programming. In Gibbons, de Moor [45], pp. 41–60
Gibbons, J.: Design patterns as higher-order datatype-generic programs (June 2005), Tutorial presented at ECOOP, http://2005.ecoop.org /8.html
Gibbons, J.: Design patterns as higher-order datatype-generic programs (October 2005), Tutorial presented at OOPSLA, http://www.oopsla.org /2005/ShowEvent.do?id=121
Gibbons, J.: Design patterns as higher-order datatype-generic programs. In: Hinze, R. (ed.) Workshop on Generic Programming (September 2006)
Gibbons, J.: Metamorphisms: Streaming representation-changers. Science of Computer Programming 65, 108–139 (2007)
Gibbons, J., Backhouse, R., Oliveira, B., Reig, F.: Datatype-generic programming project (2003), http://web.comlab.ox.ac.uk /oucl/research/pdt/ap/dgp/
Gibbons, J., Oliveira, B.C.d.S.: The essence of the Iterator pattern. In: Uustalu, T., McBride, C. (eds.) Mathematically-Structured Functional Programming (2006)
Gibbons, J., de Moor, O. (eds.).: The Fun of Programming. Cornerstones in Computing, Palgrave (2003), ISBN 1-4039-0772-2
Gibbons, J., Hutton, G., Altenkirch, T.: When is a function a fold or an unfold? Electronic Notes in Theoretical Computer Science. In: Proceedings of Coalgebraic Methods in Computer Science, vol. 44(1) (2001)
Gibbons, J., Jeuring, J.: Generic Programming. Kluwer Academic Publishers, Dordrecht (2003)
Gibbons, J., Jones, G.: The under-appreciated unfold. In: Proceedings of the Third ACM SIGPLAN International Conference on Functional Programming, pp. 273–279, Baltimore, Maryland (September 1998)
Gibbons, J., Lester, D., Bird, R.: Enumerating the rationals. Journal of Functional Programming 16, 281–291 (2006)
Gill, A., Launchbury, J., Peyton Jones, S.: A short cut to deforestation. In: Functional Programming Languages and Computer Architecture (1993)
Girard, J.-Y.: Interprétation Fonctionnelle et Élimination des Coupures de l’Arithmétique d’Ordre Supérieur. PhD thesis, Université de Paris VII (1972)
Gorlatch, S., Lengauer, C.: Parallelization of divide-and-conquer in the Bird-Meertens Formalism. Formal Aspects of Computing 3 (1995)
Gregor, D., Järvi, J., Siek, J.G., Reis, G.D., Stroustrup, B., Lumsdaine, A.: Concepts: Linguistic support for generic programming in C++. In: Object-Oriented Programming, Systems, Languages, and Applications (2006)
Gregor, D., Schupp, S.: Making the usage of STL safe. In: Gibbons, Jeuring [47], pp. 127–140
Guttag, J.V., Horning, J.J., Garland, S.J., Jones, K.D., Modet, A., Wing, J.M.: Larch: Languages and Tools for Formal Specification. Texts and Monographs in Computer Science. Springer, New York (1993)
Hagino, T.: A Categorical Programming Language. PhD thesis, Department of Computer Science, University of Edinburgh (September 1987)
Hinze, R.: Polytypic values possess polykinded types. In: Backhouse, R.C., Oliveira, J.N. (eds.) MPC 2000. LNCS, vol. 1837, pp. 2–27. Springer, Heidelberg (2000)
Hinze, R.: Generics for the masses. In: International Conference on Functional Programming, pp. 236–243. ACM Press, New York (2004)
Hinze, R.: Church numerals, twice! Journal of Functional Programming 15(1), 1–13 (2005)
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)
Hinze, R., Jeuring, J., Löh, A.: Comparing approaches to generic programming in Haskell. In this volume (2006)
Hinze, R., Peyton Jones, S.: Derivable type classes. In: Haskell Workshop (2000)
Hinze, R., Löh, A.: Generic programming, now! In this volume (2006)
Hoare, C.A.R.: Notes on data structuring. In: Dahl, O.-J., Dijkstra, E.W., Hoare, C.A.R. (eds.) Structured Programming, APIC studies in data processing, pp. 83–174. Academic Press, London (1972)
Hoogendijk, P., Backhouse, R.: When do datatypes commute? In: Moggi, E., Rosolini, G. (eds.) CTCS 1997. LNCS, vol. 1290, pp. 242–260. Springer, Heidelberg (1997)
Hughes, J.: Why functional programming matters. Computer Journal 32(2), 98–107 (1989)
Iverson, K.E.: A Programming Language. Wiley, Chichester (1962)
Jansson, P., Jeuring, J.: PolyP - a polytypic programming language extension. In: Principles of Programming Languages, pp. 470–482 (1997)
Jansson, P.: Functional Polytypic Programming. PhD thesis, Computing Science, Chalmers University of Technology and Göteborg University, Sweden (May 2000)
Jansson, P., Jeuring, J.: Polytypic data conversion programs. Science of Computer Programming 43(1), 35–75 (2002)
Jay, B., Steckler, P.: The functional imperative: Shape! In: Hankin, C. (ed.) ESOP 1998 and ETAPS 1998. LNCS, vol. 1381, pp. 139–153. Springer, Heidelberg (1998)
Jay, C.B.: A semantics for shape. Science of Computer Programming 25(2-3), 251–283 (1995)
Jenks, R.D., Sutor, R.S.: Axiom: The Scientific Computing System. Springer, Heidelberg (1992)
Jensen, K., Wirth, N.: Pascal User Manual and Report. Springer, Heidelberg (1975)
Jesperson, H.: POSIX shell and utilities (p1003.2) (September 1991), Draft 11.2 http://www.nic.funet.fi /pub/doc/posix/p1003.2/
Jeuring, J., Meijer, E. (eds.): Advanced Functional Programming. LNCS, vol. 925. Springer, Heidelberg (1995)
Jones, M.P., Duponcheel, L.: Composing monads. Technical Report RR-1004, Department of Computer Science, Yale (December 1993)
Kabanov, J., Vene, V.: Recursion schemes for dynamic programming. In: Uustalu, T. (ed.) MPC 2006. LNCS, vol. 4014, Springer, Heidelberg (2006)
Kahn, J.: It’s alive! Wired, 10.03:72-77 (March 2002)
Kennedy, A., Syme, D.: Design and implementation of generics for the.NET Common Language Runtime. In: Programming Language Design and Implementation, Snowbird, Utah, pp. 1–12 (2001)
Kiczales, G., des Riviéres, J., Bobrow, D.G.: The Art of the Metaobject Protocol. MIT Press, Cambridge (1991)
Kiczales, G., Lamping, J., Menhdhekar, A., Maeda, C., Lopes, C., Loingtier, J.-M., Irwin, J.: Aspect-oriented programming. In: Aksit, M., Matsuoka, S. (eds.) ECOOP 1997. LNCS, vol. 1241, pp. 220–242. Springer, Heidelberg (1997)
King, D.J., Wadler, P.: Combining monads. In: Launchbury, J., Sansom, P.M. (eds.) Functional Programming, Glasgow 1992, Springer, Heidelberg (1993)
Kiselyov, O., Lämmel, R.: Haskell’s Overlooked Object System. Technical Report cs/0509027, arXiv.org (September 2005)
Korte, B., Lovász, L., Schrader, R.: Greedoids. Springer, Heidelberg (1991)
Kühne, T.: Internal iteration externalized. In: Guerraoui, R. (ed.) ECOOP 1999. LNCS, vol. 1628, pp. 329–350. Springer, Heidelberg (1999)
Lazic, R.: A Semantic Study of Data Independence with Applications to Model Checking. D.Phil. thesis, Oxford University Computing Laboratory (1999)
Lazic, R., Nowak, D.: On a semantic definition of data independence. In: Hofmann, M.O. (ed.) TLCA 2003. LNCS, vol. 2701, pp. 226–240. Springer, Heidelberg Technical Report CS-RR-392, Department of Computer Science, University of Warwick (2003)
Liskov, B.: A history of CLU. ACM SIGPLAN Notices 28(3), 133–147 (1993)
Liskov, B., Guttag, J.: Abstraction and Specification in Program Development. MIT Electrical Engineering and Computer Science Series. MIT Press, Cambridge (1986)
Löh, A.:Exploring Generic Haskell. PhD thesis, Utrecht University (2004)
Malcolm, G.: Data structures and program transformation. Science of Computer Programming 14, 255–279 (1990)
Martin, U., Nipkow, T.: Automating Squiggol. In: Broy, M., Jones, C.B. (eds.) IFIP TC2 Working Conference on Programming Concepts and Methods, Sea of Galilee, Israel, pp. 233–246. North-Holland, Amsterdam (1990)
McBride, C.: Naperian functors. Personal communication by email (5th April 2006)
McBride, C., Paterson, R.: Applicative programming with effects. Journal of Functional Programming (to appear)
McKinna, J.: Why dependent types matter. In: Principles of Programming Languages (2006)
Meacham, J.: DrIFT homepage (2004), http://repetae.net /~john/computer/haskell/DrIFT/
Meertens, L.: Paramorphisms. Formal Aspects of Computing 4(5), 413–424 (1992)
Meertens, L.: Calculate polytypically! In: Kuchen, H., Swierstra, S.D. (eds.) PLILP 1996. LNCS, vol. 1140, pp. 1–16. Springer, Heidelberg (1996)
Meertens, L.: Functor pulling. In: Backhouse, R., Sheard, T. (eds.) Workshop on Generic Programming, Marstrand, Sweden (1998)
Meijer, E., Fokkinga, M., Paterson, R.: Functional programming with bananas, lenses, envelopes and barbed wire. In: Hughes, J. (ed.) Functional Programming Languages and Computer Architecture. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991)
Meijer, E., Jeuring, J.: Merging monads and folds for functional programming. In: Jeuring and Meijer [76]
Milner, R.: A theory of type polymorphism in programming. Journal of Computer and System Sciences 17, 348–375 (1978)
Milner, R., Tofte, M., Harper, R., MacQueen, D.: Definition of Standard ML. revised edn., MIT Press, Cambridge (1997)
Moggi, E.: Notions of computation and monads. Information and Computation 93(1) (1991)
Moggi, E., Bellé, G., Barry Jay, C.: shapely functors and traversals. In: Hoffman, M., Pavlovic, D., Rosolini, P. (eds.) Category Theory in Computer Science (1999)
Musser, D.R., Stepanov, A.A.: The Ada Generic Library linear list processing packages. Springer, New York (1989)
Naur, P., Backus, J.W., Bauer, F.L., Green, J., Katz, C., McCarthy, J., Perlis, A.J., Rutishauser, H., Samelson, K., Vauquois, B., Wegstein, J.H., van Wijngaarden, A., Woodger, M.: Revised report on the algorithmic language ALGOL 60. Communications of the ACM 6(1), 1–17 (1963)
Pardo, A.: Fusion of recursive programs with computation effects. Theoretical Computer Science 260, 165–207 (2001)
Pardo, A.: Combining datatypes and effects. In: Vene, V., Uustalu, T. (eds.) AFP 2004. LNCS, vol. 3622, pp. 171–209. Springer, Heidelberg (2005)
Perlis, A.J., Samelson, K.: Preliminary report: International Algebraic Language. Communications of the ACM 1(12), 8–22 (1958)
Peyton Jones, S.: The Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press, Cambridge (2003)
Peyton Jones, S., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unification-based type inference for generalized algebraic data types. In: International Conference on Functional Programming (2006)
Peyton Jones, S., Wadler, P.: Imperative functional programming. In: Principles of Programming Languages, pp. 71–84 (1993)
Programatica Team. Programatica tools for certifiable, auditable development of high-assurance systems in Haskell. In: High Confidence Software and Systems Conference. National Security Agency (April 2003)
Reynolds, J.C.: Towards a theory of type structure. In: Robinet, B. (ed.) Programming Symposium. LNCS, vol. 19, pp. 408–425. Springer, Heidelberg (1974)
Reynolds, J.C.: Types, abstraction and parametric polymorphism. In: Information Processing 1983, pp. 513–523. Elsevier, Amsterdam (1983)
Ruehr, F.: Analytical and Structural Polymorphism Expressed Using Patterns over Types. PhD thesis, University of Michigan (1992)
Tim Sheard. Generic programming in Ωmega. In: this volume (2006)
Siek, J., Lee, L.-Q., Lumsdaine, A.: The Boost Graph Library. Addison-Wesley, Reading (2002)
Siek, J., Lumsdaine, A.: Essential language support for generic programming. In: Programming Language Design and Implementation, pp. 73–84 (2005)
Skillicorn, D.B.: The Bird-Meertens Formalism as a parallel model. In: Kowalik, J.S., Grandinetti, L. (eds.) Software for Parallel Computation. NATO ASI Series F, vol. 106, Springer, Heidelberg (1993)
STOP project. International Summer School on Constructive Algorithmics, Hollum, Ameland (1989)
Strachey, C.: Fundamental concepts in programming languages. Higher-Order and Symbolic Computation. Lecture notes from Summer School in Computer Programming 13(1/2), 1–49 (2000)
Taha, W.: A gentle introduction to multi-stage programming. In: Lengauer, C., Batory, D., Consel, C., Odersky, M. (eds.) Domain-Specific Program Generation. LNCS, vol. 3016, pp. 30–50. Springer, Heidelberg (2004)
Unruh, E.: Prime number computation. ANSI X3J16-94-0075/ISO WG21-462 (1994)
Uustalu, T., Vene, V.: Primitive (co)recursion and course-of-value (co)iteration. Informatica 10(1), 5–26 (1999)
van Wijngaarden, A., Mailloux, B.J., Peck, J.E.L., Koster, C.H.A., Sintzoff, M., Lindsey, C.H., Meertens, L.G.L.T., Fisker, R.G.: Revised report on the algorithmic language ALGOL 68. Acta Informatica 5(1-3) (1975)
Veldhuizen, T.: Active Libraries and Universal Languages. PhD thesis, Computer Science, Indiana University (2004)
Vene, V., Uustalu, T.: Functional programming with apomorphisms (corecursion). Proceedings of the Estonian Academy of Sciences: Physics, Mathematics. In: 9th Nordic Workshop on Programming Theory 47(3), 147–161 (1998)
Vytiniotis, D., Washburn, G., Weirich, S.: An open and shut typecase. In: International Conference on Functional Programming (2004)
Wadler, P.: Theorems for free! In Functional Programming Languages and Computer Architecture, pp. 347–359. ACM, New York (1989)
Wadler, P.: Deforestation: Transforming programs to eliminate trees. Theoretical Computer Science 73, 231–248 (1990)
Wadler, P.: Comprehending monads. Mathematical Structures in Computer Science 2(4), 461–493 (1992)
Wadler, P.: Monads for functional programming. In: Broy, M. (ed.) Program Design Calculi: Proceedings of the Marktoberdorf Summer School. Also in [76] (1992)
Wadler, P.: How to solve the reuse problem? Functional programming. In: International Conference on Software Reuse, pp. 371–372. IEEE, Los Alamitos (1998), http://doi.ieeecomputersociety.org /10.1109/ICSR.1998.685772
Wadler, P.L.: The expression problem. Posting to java-genericity mailing list (November 12, 1998)
Wirth, N., Hoare, C.A.R.: A contribution to the development of ALGOL. Communications of the ACM 9(6), 413–432 (1966)
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 2007 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Gibbons, J. (2007). Datatype-Generic Programming. In: Backhouse, R., Gibbons, J., Hinze, R., Jeuring, J. (eds) Datatype-Generic Programming. SSDGP 2006. Lecture Notes in Computer Science, vol 4719. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-76786-2_1
Download citation
DOI: https://doi.org/10.1007/978-3-540-76786-2_1
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-76785-5
Online ISBN: 978-3-540-76786-2
eBook Packages: Computer ScienceComputer Science (R0)