Type-Indexed Data Types

  • Ralf Hinze
  • Johan Jeuring
  • Andres Löh
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 2386)

Abstract

A polytypic function is a function that can be instantiated on many data types to obtain data type specific functionality. Examples of polytypic functions are the functions that can be derived in Haskell, such as show, read, and ‘==’. More advanced examples are functions for digital searching, pattern matching, unification, rewriting, and structure editing. For each of these problems, we not only have to define polytypic functionality, but also a type-indexed data type: a data type that is constructed in a generic way from an argument data type. For example, in the case of digital searching we have to define a search tree type by induction on the structure of the type of search keys. This paper shows how to define type-indexed data types, discusses several examples of type-indexed data types, and shows how to specialize type-indexed data types. The approach has been implemented in Generic Haskell, a generic programming extension of the functional language Haskell.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    R. Backhouse, P. Jansson, J. Jeuring, and L. Meertens. Generic programming: An introduction. In S. Doaitse Swierstra, Pedro R. Henriques, and José N. Oliveira, editors, Advanced Functional Programming, volume 1608 of LNCS, pages 28–115. Springer-Verlag, 1999.CrossRefGoogle Scholar
  2. 2.
    Richard Bird, Oege de Moor, and Paul Hoogendijk. Generic functional programming with types and relations. Journal of Functional Programming, 6(1):1–28, 1996.MATHMathSciNetCrossRefGoogle Scholar
  3. 3.
    Manuel M.T. Chakravarty and Gabriele Keller. More types for nested data parallel programming. In Proceedings ICFP 2000: International Conference on Functional Programming, pages 94–105. ACM Press, 2000.Google Scholar
  4. 4.
    Koen Claessen and Peter Ljunglöf. Typed logical variables in Haskell. In Proceedings Haskell Workshop 2000, 2000.Google Scholar
  5. 5.
    Karl Crary and Stephanie Weirich. Flexible type analysis. In Proceedings ICFP 1999: International Conference on Functional Programming, pages 233–248. ACM Press, 1999.Google Scholar
  6. 6.
    Karl Crary, Stephanie Weirich, and J. Gregory Morrisett. Intensional polymorphism in type-erasure semantics. In Proceedings ICFP 1998: International Conference on Functional Programming, pages 301–312. ACM Press, 1998.Google Scholar
  7. 7.
    C. Dubois, F. Rouaix, and P. Weis. Extensional polymorphism. In 22nd Symposium on Principles of Programming Languages, POPL’ 95, pages 118–129, 1995.Google Scholar
  8. 8.
    M.M. Fokkinga. Law and Order in Algorithmics. PhD thesis, University of Twente, Dept INF, Enschede, The Netherlands, 1992.Google Scholar
  9. 9.
    Jeremy Gibbons. Polytypic downwards accumulations. In Proceedings of Mathematics of Program Construction, volume 1422 of LNCS. Springer-Verlag, June 1998.CrossRefGoogle Scholar
  10. 10.
    Robert Harper and Greg Morrisett. Compiling polymorphism using intensional type analysis. In 22nd Symposium on Principles of Programming Languages, POPL’ 95, pages 130–141, 1995.Google Scholar
  11. 11.
    Ralf Hinze. Generalizing generalized tries. Journal of Functional Programming, 10(4):327–351, 2000.MATHCrossRefMathSciNetGoogle Scholar
  12. 12.
    Ralf Hinze. Generic Programs and Proofs. 2000. Habilitationsschrift, Bonn University.Google Scholar
  13. 13.
    Ralf Hinze. A new approach to generic functional programming. In Conference Record of POPL’ 00: The 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 119–132. ACM Press, 2000.Google Scholar
  14. 14.
    Ralf Hinze. Polytypic values possess polykinded types. In Roland Backhouse and José Nuno Oliveira, editors, Mathematics of Program Construction, volume 1837 of LNCS, pages 2–27. Springer-Verlag, 2000.CrossRefGoogle Scholar
  15. 15.
    Ralf Hinze and Simon Peyton Jones. Derivable type classes. In Graham Hutton, editor, Proceedings of the 2000 ACM SIGPLAN Haskell Workshop, volume 41.1 of Electronic Notes in Theoretical Computer Science. Elsevier Science, August 2001. The preliminary proceedings appeared as a University of Nottingham technical report.Google Scholar
  16. 16.
    Gérard Huet. The zipper. Journal of Functional Programming, 7(5):549–554, 1997.MATHCrossRefMathSciNetGoogle Scholar
  17. 17.
    P. Jansson and J. Jeuring. PolyP — a polytypic programming language extension. In Conference Record of POPL’ 97: The 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 470–482. ACM Press, 1997.Google Scholar
  18. 18.
    Patrik Jansson. The WWW home page for polytypic programming. Available from http://www.cs.chalmers.se/~patrikj/poly/, 2001.
  19. 19.
    Patrik Jansson and Johan Jeuring. Functional pearl: Polytypic unification. Journal of Functional Programming, 8(5):527–536, September 1998.Google Scholar
  20. 20.
    Patrik Jansson and Johan Jeuring. A framework for polytypic programming on terms, with an application to rewriting. In J. Jeuring, editor, Workshop on Generic Programming 2000, Ponte de Lima, Portugal, July 2000, pages 33–45, 2000. Utrecht Technical Report UU-CS-2000-19.Google Scholar
  21. 21.
    C.B. Jay, G. Bellè, and E. Moggi. Functorial ML. Journal of Functional Programming, 8(6):573–619, 1998.MATHCrossRefMathSciNetGoogle Scholar
  22. 22.
    J. Jeuring. Polytypic pattern matching. In Conference Record of FPCA’ 95, SIGPLAN-SIGARCH-WG2.8 Conference on Functional Programming Languages and Computer Architecture, pages 238–248. ACM Press, 1995.Google Scholar
  23. 23.
    Mark P. Jones. Type classes with functional dependencies. In G. Smolka, editor, Proceedings of the 9th European Symposium on Programming, ESOP 2000, Berlin, Germany, volume 1782 of LNCS, pages 230–244. Springer-Verlag, March 2000.Google Scholar
  24. 24.
    Ralf Lämmel and Wolfgang Lohmann. Format Evolution. In J. Kouloumdjian, H.C. Mayr, and A. Erkollar, editors, Proc. 7th International Conference on Reverse Engineering for Information Systems (RETIS 2001), volume 155 of books@ocg.at, pages 113–134. OCG, 2001.Google Scholar
  25. 25.
    G. Malcolm. Data structures and program transformation. Science of Computer Programming, 14:255–279, 1990.CrossRefMathSciNetMATHGoogle Scholar
  26. 26.
    Connor McBride. The derivative of a regular type is its type of one-hole contexts. Unpublished manuscript, 2001.Google Scholar
  27. 27.
    Nancy J. McCracken. An investigation of a programming language with a polymorphic type structure. PhD thesis, Syracuse University, June 1979.Google Scholar
  28. 28.
    L. Meertens. Paramorphisms. Formal Aspects of Computing, 4(5):413–425, 1992.MATHCrossRefGoogle Scholar
  29. 29.
    E. Meijer, M.M. Fokkinga, and R. Paterson. Functional programming with bananas, lenses, envelopes, and barbed wire. In J. Hughes, editor, FPCA’91: Functional Programming Languages and Computer Architecture, volume 523 of LNCS, pages 124–144. Springer-Verlag, 1991.Google Scholar
  30. 30.
    John C. Mitchell. Foundations for Programming Languages. The MIT Press, 1996.Google Scholar
  31. 31.
    Simon Peyton Jones [editor], John Hughes [editor], Lennart Augustsson, Dave Barton, Brian Boutel, Warren Burton, Simon Fraser, Joseph Fasel, Kevin Hammond, Ralf Hinze, Paul Hudak, Thomas Johnsson, Mark Jones, John Launchbury, Erik Meijer, John Peterson, Alastair Reid, Colin Runciman, and Philip Wadler. Haskell 98 — A non-strict, purely functional language. Available from http://www.haskell.org/definition/, February 1999.
  32. 32.
    Valery Trifonov, Bratin Saha, and Zhong Shao. Fully reflexive intensional type analysis. In Proceedings ICFP 2000: International Conference on Functional Programming, pages 82–93. ACM Press, 2000.Google Scholar
  33. 33.
    Måns Vestin. Genetic algorithms in Haskell with polytypic programming. Examensarbeten 1997:36, Göteborg University, Gothenburg, Sweden, 1997. Available from the Polytypic programming WWW page [18].Google Scholar
  34. 34.
    Stephanie Weirich. Encoding intensional type analysis. In European Symposium on Programming, volume 2028 of LNCS, pages 92–106. Springer-Verlag, 2001.Google Scholar
  35. 35.
    Jan de Wit. A technical overview of Generic Haskell. Master’s thesis, Department of Information and Computing Sciences, Utrecht University, 2002.Google Scholar
  36. 36.
    Zhe Yang. Encoding types in ML-like languages. In Proceedings ICFP 1998: International Conference on Functional Programming, pages 289–300. ACM Press, 1998.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2002

Authors and Affiliations

  • Ralf Hinze
    • 1
    • 2
  • Johan Jeuring
    • 2
    • 3
  • Andres Löh
    • 2
  1. 1.Institut für Informatik IIIUniversität BonnBonnGermany
  2. 2.Institute of Information and Computing SciencesUtrecht UniversityUtrechtThe Netherlands
  3. 3.Open UniversityHeerlenThe Netherlands

Personalised recommendations