Polytypic programming

  • Johan Jeuring
  • Patrik Jansson
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 1129)


Many functions have to be written over and over again for different datatypes, either because datatypes change during the development of programs, or because functions with similar functionality are needed on different datatypes. Examples of such functions are pretty printers, debuggers, equality functions, unifiers, pattern matchers, rewriting functions, etc. Such functions are called polytypic functions. A polytypic function is a function that is defined by induction on the structure of user-defined datatypes. This paper introduces polytypic functions, and shows how to construct and reason about polytypic functions. A larger example is studied in detail: polytypic functions for term rewriting and for determining whether a collection of rewrite rules is normalising.


Normal Form Pattern Match Function Length Function Match Function Size 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Patrik Berglund. A polytypic rewriting system. Master's thesis, Chalmers University of Technology, 1996. Forthcoming.Google Scholar
  2. 2.
    C. Böhm and A. Berarducci. Automatic synthesis of type λ-programs on term algebras. Theoretical Computer Science, 39:135–154, 1985.Google Scholar
  3. 3.
    Richard Bird, Oege de Moor, and Paul Hoogendijk. Generic programming with relations and functors. To appear in Journal of Functional Programming, 1996.Google Scholar
  4. 4.
    R.S. Bird. An introduction to the theory of lists. In M. Broy, editor, Logic of Programming and Calculi of Discrete Design, volume F36 of NATO ASI Series, pages 5–42. Springer-Verlag, 1987.Google Scholar
  5. 5.
    R.S. Bird. Lectures on constructive functional programming. In M. Broy, editor, Constructive Methods in Computing Science, volume F55 of NATO ASI Series, pages 151–216. Springer-Verlag, 1989.Google Scholar
  6. 6.
    R. Cockett and T. Fukushima. About charity. Unpublished article, see, 1992.Google Scholar
  7. 7.
    M. Flore et al. Domains and denotational semantics: History, accomplishments and open problems. Available via WWW:, 1996.Google Scholar
  8. 8.
    J.H. Fasel, P. Hudak, S. Peyton Jones, and P. Wadler. Sigplan Notices Special Issue on the Functional Programming Language Haskell. ACM SIGPLAN notices, 27(5), 1992.Google Scholar
  9. 9.
    Leonidas Fegaras and Tim Sheard. Revisiting catamorphisms over datatypes with embedded functions. In Proceedings Principles of Programming Languages, POPL '96, 1996.Google Scholar
  10. 10.
    M.M. Fokkinga. Law and order in algorithmics. PhD thesis, Twente University, 1992.Google Scholar
  11. 11.
    P. Freyd. Recursive types reduced to inductive types. In Proceedings Logic in Computer Science, LICS '90, pages 498–507, 1990.Google Scholar
  12. 12.
    E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns — Elements of Reusable Object-Oriented Software. Addison-Wesley Publishing Company, 1995.Google Scholar
  13. 13.
    T. Hagino. Category Theoretic Approach to Data Types. PhD thesis, University of Edinburgh, 1987.Google Scholar
  14. 14.
    P. Jansson. Polytypism and polytypic unification. Master's thesis, Chalmers University of Technology and University of Göteborg, 1995.Google Scholar
  15. 15.
    P. Jansson and J. Jeuring. Polytypic unification — implementing polytypic functions with constructor classes. Submitted for publication, see, 1996.Google Scholar
  16. 16.
    P. Jansson and J. Jeuring. Type inference for polytypic functions. In preparation, see, 1996.Google Scholar
  17. 17.
    C. Barry Jay. Polynomial polymorphism. In Proceedings of the Eighteenth Australasian Computer Science Conference, pages 237–243, 1995.Google Scholar
  18. 18.
    C. Barry Jay. A semantics for shape. Science of Computer Programming, 25:251–283, 1995.Google Scholar
  19. 19.
    J. Jeuring. Algorithms from theorems. In M. Broy and C.B. Jones, editors, Programming Concepts and Methods, pages 247–266. North-Holland, 1990.Google Scholar
  20. 20.
    J. Jeuring. Polytypic pattern matching. In S. Peyton Jones, editor, Conference Record of FPCA '95, SIGPLAN-SIGARCH-WG2.8 Conference on Functional Programming Languages and Computer Architecture, pages 238–248, 1995.Google Scholar
  21. 21.
    J. Jeuring. Polytypic data compression. In preparation, 1996.Google Scholar
  22. 22.
    Mark P. Jones. Functional programming with overloading and higher-order polymorphism. In J. Jeuring and E. Meijer, editors, Advanced Functional Programming, LNCS 925, pages 97–136. Springer-Verlag, 1995.Google Scholar
  23. 23.
    Mark P. Jones. Gofer. Available via ftp on, 1995.Google Scholar
  24. 24.
    J.W. Klop. Term rewriting systems. In Handbook of Logic in Computer Science, pages 1–116. Oxford University Press, 1992.Google Scholar
  25. 25.
    K. Knight. Unification: A multidisciplinary survey. Computing Surveys, 21(1), 1989.Google Scholar
  26. 26.
    D.J. Lehmann and M.B. Smyth. Algebraic specification of data types: A synthetic approach. Math. Systems Theory, 14:97–139, 1981.Google Scholar
  27. 27.
    K.J. Lieberherr, I. Silva-Lepe, and C. Xiao. Adaptive object-oriented programming — using graph-based customization. Communications of the ACM, pages 94–101, 1994.Google Scholar
  28. 28.
    G. Malcolm. Data structures and program transformation. Science of Computer Programming, 14:255–279, 1990.Google Scholar
  29. 29.
    E.G. Manes and M.A. Arbib. Algebraic Approaches to Program Semantics. Text and Monographs in Computer Science. Springer Verlag, 1986.Google Scholar
  30. 30.
    L. Meertens. Paramorphisms. Formal Aspects of Computing, 4(5):413–425, 1992.Google Scholar
  31. 31.
    E. Meijer, M. Fokkinga, and R. Paterson. Functional programming with bananas, lenses, envelopes, and barbed wire. In J. Hughes, editor, Proceedings of the 5th ACM Conference on Functional Programming Languages and Computer Architecture, FPCA '91, pages 124–144, 1991.Google Scholar
  32. 32.
    E. Meijer and G. Hutton. Bananas in space: Extending fold and unfold to exponential types. In S. Peyton Jones, editor, Conference Record of FPCA '95, SIGPLAN-SIGARCH-WG2.8 Conference on Functional Programming Languages and Computer Architecture, pages 324–333, 1995.Google Scholar
  33. 33.
    E. Meijer and J. Jeuring. Merging monads and folds for functional programming. In J. Jeuring and E. Meijer, editors, Advanced Functional Programming, LNCS 925, pages 228–266. Springer-Verlag, 1995.Google Scholar
  34. 34.
    O. de Moor. Categories, relations and dynamic programming. PhD thesis, Oxford University, 1992. Technical Monograph PRG-98.Google Scholar
  35. 35.
    O. de Moor. Categories, relations and dynamic programming. Mathematical Structures in Computer Science, 4:33–69, 1994.Google Scholar
  36. 36.
    J. Palsberg, C. Xiao, and K. Lieberherr. Efficient implementation of adaptive software. TOPLAS, 1995.Google Scholar
  37. 37.
    J.C. Reynolds. Types, abstraction, and parametric polymorphism. In R.E.A. Mason, editor, Information Processing 83, pages 513–523, 1983.Google Scholar
  38. 38.
    Fritz Ruehr. Analytical and structural polymorphism. Unpublished manuscript, 1992.Google Scholar
  39. 39.
    Fritz Ruehr. Analytical and Structural Polymorphism Expressed Using Patterns Over Types. PhD thesis, University of Michigan, 1992.Google Scholar
  40. 40.
    T. Sheard. Type parametric programming. Oregon Graduate Institute of Science and Technology, Portland, OR, USA, 1993.Google Scholar
  41. 41.
    T. Sheard and N. Nelson. Type safe abstractions using program generators. Unpublished manuscript, 1995.Google Scholar
  42. 42.
    Tim Sheard. Automatic generation and use of abstract structure operators. ACM Transactions on Programming Languages and Systems, 13(4):531–557, 1991.Google Scholar
  43. 43.
    A. Takano and E. Meijer. Shortcut deforestation in calculational form. In S. Peyton Jones, editor, Conference Record of FPCA '95, SIGPLAN-SIGARCH-WG2.8 Conference on Functional Programming Languages and Computer Architecture, pages 306–313, 1995.Google Scholar
  44. 44.
    P. Wadler. Theorems for free! In Functional Programming Languages and Computer Architecture, FPCA '89, pages 347–359. ACM Press, 1989.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1996

Authors and Affiliations

  • Johan Jeuring
    • 1
    • 2
  • Patrik Jansson
    • 1
    • 2
  1. 1.Chalmers University of TechnologyGöteborgSweden
  2. 2.University of GöteborgGöteborgSweden

Personalised recommendations