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.
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
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.
Richard Bird, Oege de Moor, and Paul Hoogendijk. Generic functional programming with types and relations. Journal of Functional Programming, 6(1):1–28, 1996.
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.
Koen Claessen and Peter Ljunglöf. Typed logical variables in Haskell. In Proceedings Haskell Workshop 2000, 2000.
Karl Crary and Stephanie Weirich. Flexible type analysis. In Proceedings ICFP 1999: International Conference on Functional Programming, pages 233–248. ACM Press, 1999.
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.
C. Dubois, F. Rouaix, and P. Weis. Extensional polymorphism. In 22nd Symposium on Principles of Programming Languages, POPL’ 95, pages 118–129, 1995.
M.M. Fokkinga. Law and Order in Algorithmics. PhD thesis, University of Twente, Dept INF, Enschede, The Netherlands, 1992.
Jeremy Gibbons. Polytypic downwards accumulations. In Proceedings of Mathematics of Program Construction, volume 1422 of LNCS. Springer-Verlag, June 1998.
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.
Ralf Hinze. Generalizing generalized tries. Journal of Functional Programming, 10(4):327–351, 2000.
Ralf Hinze. Generic Programs and Proofs. 2000. Habilitationsschrift, Bonn University.
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.
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.
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.
Gérard Huet. The zipper. Journal of Functional Programming, 7(5):549–554, 1997.
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.
Patrik Jansson. The WWW home page for polytypic programming. Available from http://www.cs.chalmers.se/~patrikj/poly/, 2001.
Patrik Jansson and Johan Jeuring. Functional pearl: Polytypic unification. Journal of Functional Programming, 8(5):527–536, September 1998.
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.
C.B. Jay, G. Bellè, and E. Moggi. Functorial ML. Journal of Functional Programming, 8(6):573–619, 1998.
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.
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.
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.
G. Malcolm. Data structures and program transformation. Science of Computer Programming, 14:255–279, 1990.
Connor McBride. The derivative of a regular type is its type of one-hole contexts. Unpublished manuscript, 2001.
Nancy J. McCracken. An investigation of a programming language with a polymorphic type structure. PhD thesis, Syracuse University, June 1979.
L. Meertens. Paramorphisms. Formal Aspects of Computing, 4(5):413–425, 1992.
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.
John C. Mitchell. Foundations for Programming Languages. The MIT Press, 1996.
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.
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.
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].
Stephanie Weirich. Encoding intensional type analysis. In European Symposium on Programming, volume 2028 of LNCS, pages 92–106. Springer-Verlag, 2001.
Jan de Wit. A technical overview of Generic Haskell. Master’s thesis, Department of Information and Computing Sciences, Utrecht University, 2002.
Zhe Yang. Encoding types in ML-like languages. In Proceedings ICFP 1998: International Conference on Functional Programming, pages 289–300. ACM Press, 1998.
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2002 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Hinze, R., Jeuring, J., Löh, A. (2002). Type-Indexed Data Types. In: Boiten, E.A., Möller, B. (eds) Mathematics of Program Construction. MPC 2002. Lecture Notes in Computer Science, vol 2386. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-45442-X_10
Download citation
DOI: https://doi.org/10.1007/3-540-45442-X_10
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-43857-1
Online ISBN: 978-3-540-45442-7
eBook Packages: Springer Book Archive