Type-Indexed Data Types
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.
KeywordsEditing Barb Meijer
Unable to display preview. Download preview PDF.
- 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.Koen Claessen and Peter Ljunglöf. Typed logical variables in Haskell. In Proceedings Haskell Workshop 2000, 2000.Google Scholar
- 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.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.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.M.M. Fokkinga. Law and Order in Algorithmics. PhD thesis, University of Twente, Dept INF, Enschede, The Netherlands, 1992.Google Scholar
- 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
- 12.Ralf Hinze. Generic Programs and Proofs. 2000. Habilitationsschrift, Bonn University.Google Scholar
- 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
- 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
- 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.Patrik Jansson. The WWW home page for polytypic programming. Available from http://www.cs.chalmers.se/~patrikj/poly/, 2001.
- 19.Patrik Jansson and Johan Jeuring. Functional pearl: Polytypic unification. Journal of Functional Programming, 8(5):527–536, September 1998.Google Scholar
- 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
- 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.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.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 firstname.lastname@example.org, pages 113–134. OCG, 2001.Google Scholar
- 26.Connor McBride. The derivative of a regular type is its type of one-hole contexts. Unpublished manuscript, 2001.Google Scholar
- 27.Nancy J. McCracken. An investigation of a programming language with a polymorphic type structure. PhD thesis, Syracuse University, June 1979.Google Scholar
- 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.John C. Mitchell. Foundations for Programming Languages. The MIT Press, 1996.Google Scholar
- 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.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.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 .Google Scholar
- 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.Jan de Wit. A technical overview of Generic Haskell. Master’s thesis, Department of Information and Computing Sciences, Utrecht University, 2002.Google Scholar
- 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