Hostname: page-component-8448b6f56d-qsmjn Total loading time: 0 Render date: 2024-04-17T00:54:31.601Z Has data issue: false hasContentIssue false

A lightweight approach to datatype-generic rewriting

Published online by Cambridge University Press:  27 September 2010

THOMAS VAN NOORT
Affiliation:
Institute for Computing and Information Sciences, Radboud University Nijmegen, P.O. Box 9010, 6500 GL Nijmegen, The Netherlands (e-mail: thomas@cs.ru.nl)
ALEXEY RODRIGUEZ YAKUSHEV
Affiliation:
Vector Fabrics, Paradijslaan 28, 5611 KN Eindhoven, The Netherlands (e-mail: alexey@vectorfabrics.com, stefan@vectorfabrics.com)
STEFAN HOLDERMANS
Affiliation:
Vector Fabrics, Paradijslaan 28, 5611 KN Eindhoven, The Netherlands (e-mail: alexey@vectorfabrics.com, stefan@vectorfabrics.com)
JOHAN JEURING
Affiliation:
Department of Information and Computing Sciences, Utrecht University, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands and School of Computer Science, Open University of the Netherlands, P.O. Box 2960, 6401 DL Heerlen, The Netherlands (e-mail: johanj@cs.uu.nl)
BASTIAAN HEEREN
Affiliation:
School of Computer Science, Open University of the Netherlands, P.O. Box 2960, 6401 DL Heerlen, The Netherlands (e-mail: bastiaan.heeren@ou.nl)
JOSÉ PEDRO MAGALHÃES
Affiliation:
Department of Information and Computing Sciences, Utrecht University, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands (e-mail: jpm@cs.uu.nl)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

Term-rewriting systems can be expressed as generic programs parameterised over the shape of the terms being rewritten. Previous implementations of generic rewriting libraries require users to either adapt the datatypes that are used to describe these terms or to specify rewrite rules as functions. These are fundamental limitations: the former implies a lot of work for the user, while the latter makes it hard if not impossible to document, test, and analyze rewrite rules. In this article, we demonstrate how to overcome these limitations by making essential use of type-indexed datatypes. Our approach is lightweight in that it is entirely expressible in Haskell with GADTs and type families and can be readily packaged for use with contemporary Haskell distributions.

Type
Articles
Copyright
Copyright © Cambridge University Press 2010

References

Backhouse, R. C., Jansson, P., Jeuring, J. & Meertens, L. (1999) Generic programming: an introduction. In Advanced Functional Programming, Third International School, Braga, Portugal, September 12–19, 1998, Revised Lectures, Swierstra, S. D., Henriques, P. R. & Oliveira, J. N. (eds), Lecture Notes in Computer Science, vol. 1608. Springer-Verlag, pp. 28115.Google Scholar
Borovanský, P., Kirchner, C., Kirchner, H. & Ringeissen, C. (2001) Rewriting with strategies in ELAN: a functional semantics, Int. J. Found. Comput. Sci., 12 (1), 6995.CrossRefGoogle Scholar
Bravenboer, M., Kalleberg, K. T. & Visser, E. (2008) Stratego/XT 0.17: a language and toolset for program transformation. Sci. Comput. Program., 72 (1–2), 5270.CrossRefGoogle Scholar
Bringert, B. & Ranta, A. (2006) A pattern for almost compositional functions. In Proceedings of the 11th ACM SIGPLAN International Conference on Functional Programming, ICFP 2006, Portland, Oregon, USA, September 16–21, 2006, Reppy, J. H. & Lawall, J. L. (eds), ACM Press, pp. 216226.Google Scholar
Brown, N. C. C. & Sampson, A. T. (2008) Matching and modifying with generics. In Draft Proceedings of the Ninth Symposium on Trends in Functional Programming (TFP), May 26–28, 2008, Center Parcs “Het Heijderbos”, The Netherlands, Achten, P., Koopman, P. & Morazán, M. T. (eds), The draft proceedings of the symposium have been published as a technical report (ICIS-R08007) at Radboud University Nijmegen, pp. 304318.Google Scholar
Bruijn, N. G. de. (1972) Lambda calculus notation with nameless dummies: a tool for automatic formula manipulation, with application to the Church-rosser theorem, Indagaciones Mathematische, 34, 381392.Google Scholar
Chakravarty, M. M. T., Keller, G. & Peyton Jones, S. (2005a) Associated type synonyms. In Proceedings of the 10th ACM SIGPLAN International Conference on Functional Programming, ICFP 2005, Tallinn, Estonia, September 26–28, 2005, In Danvy, O. & Pierce, B. C. (eds), ACM Press, pp. 241253.Google Scholar
Chakravarty, M. M. T., Keller, G., Peyton Jones, S. & Marlow, S. (2005b) Associated types with class. In Proceedings of the 32nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2005, Long Beach, California, USA, January 12–14, 2005, Palsberg, J. & Abadi, M. (eds), ACM Press, pp. 113.Google Scholar
Claessen, K. & Hughes, J. (2000) QuickCheck: a lightweight tool for random testing of Haskell programs. In Proceedings of the Fifth ACM SIGPLAN International Conference on Functional Programming (ICFP '00), Montreal, Canada, September 18–21, 2000. ACM Press, pp. 268279.Google Scholar
Deursen, A. van, Heering, J. & Klint, P. (eds). (1996) Language Prototyping. an Algebraic Specification Approach. AMAST Series in Computing, vol. 5. Singapore: World Scientific.CrossRefGoogle Scholar
Goguen, J. & Grant, M. (1997) Algebraic Semantics of Imperative Programs. Cambridge, Massachusetts: The MIT Press.Google Scholar
Heeren, B., Jeuring, J., Leeuwen, A. van & Gerdes, A. (2008) Specifying strategies for exercises. In Intelligent Computer Mathematics, 9th International Conference, AISC 2008, 15th Symposium, Calculemus 2008, 7th International Conference, MKM 2008, Birmingham, UK, July 28–August 1, 2008, Proceedings, Autexier, S., Campbell, J., Rubio, J., Sorge, V., Suzuki, M. & Wiedijk, F. (eds), Lecture Notes in Computer Science, vol. 5144. Springer-Verlag, pp. 430445.Google Scholar
Hinze, R. (2000) Generic Programs and Proofs. Habilitationsschrift: University of Bonn.Google Scholar
Hinze, R., Jeuring, J. & Löh, A. (2004) Type-indexed data types, Sci. Comput. Program., 51 (2), 117151.CrossRefGoogle Scholar
Holdermans, S., Jeuring, J., Löh, A. & Rodriguez Yakushev, A. (2006) Generic views on data types. In Mathemathics of Program Construction, 8th International Conference, MPC 2006, Kuressaare, Estonia, July 3–5, 2006, Proceedings, Uustalu, T. (ed), Lecture Notes in Computer Science, vol. 4014. Springer-Verlag, pp. 209234.Google Scholar
Jansson, P. & Jeuring, J. (1997) PolyP: a polytypic programming language. In Conference Record of POPL'97: The 24 ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Papers Presented at the Symposium, Paris, France, 15–17 January 1997. ACM Press, pp. 68114.Google Scholar
Jansson, P. & Jeuring, J. (1998) Polytypic unification, J. Funct. Program., 8 (5), 527536.CrossRefGoogle Scholar
Jansson, P. & Jeuring, J. (2000) A framework for polytypic programming on terms, with an application to rewriting. In Proceedings Workshop on Generic Programming (WGP 2000), July 6, 2000, Ponte de Lima, Portugal, Jeuring, J. (ed), The proceedings of the workshop have been published as a technical report (UU-CS-2000-19) at Utrecht University, pp. 3345.Google Scholar
Lämmel, R. & Peyton Jones, S. (2003) Scrap your boilerplate: a practical design pattern for generic programming. In Proceedings of the ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI 2003), New Orleans, LA, USA, January 18, 2003. ACM Press, pp. 2637.Google Scholar
Lämmel, R. & Visser, J. (2002) Typed combinators for generic traversal. In Practical Aspects of Declarative Languages, 4th International Symposium, PADL 2002, Portland, OR, USA, January 19–20, 2002, Krishnamurthi, S. & Ramakrishnan, C. R. (eds), Lecture Notes in Computer Science, vol. 2257. Springer-Verlag, pp. 137154.CrossRefGoogle Scholar
Magalhães, J. P., Holdermans, S., Jeuring, J. & Löh, A. (2010) Optimizing generics is easy! In Proceedings of the 2010 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2010, Madrid, Spain, January 18–19, 2010, Gallagher, J. P. & Voigtländer, J. (eds), ACM Press, pp. 3342.Google Scholar
Mitchell, N. & Runciman, C. (2007) Uniform boilerplate and list processing. In Proceedings of the ACM SIGPLAN Workshop on Haskell, Haskell 2007, Freiburg, Germany, September 30, 2007, Keller, G. (ed), ACM Press, pp. 4960.Google Scholar
Noort, T. van, Rodriguez Yakushev, A., Holdermans, S., Jeuring, J. & Heeren, B. (2008) A lightweight approach to datatype-generic rewriting. In Proceedings of the ACM SIGPLAN Workshop on Generic Programming, WGP 2008, Victoria, BC, Canada, September 20, 2008, Hinze, R. & Syme, D. (eds), ACM Press, pp. 1324.Google Scholar
Pasalić, E. & Linger, N. (2004) Meta-programming with typed object-language representations. In Generative Programming and Component Engineering: Third International Conference, GPCE 2004, Vancouver, Canada, October 24–28, 2004, Proceedings, Karsai, G. & Visser, E. (eds), Lecture Notes in Computer Science, vol. 3286. Springer-Verlag, pp. 136167.CrossRefGoogle Scholar
Peyton Jones, S., Vytiniotis, D., Weirich, S. & Washburn, G. (2006) Simple unification-based type inference for GADTs. In Proceedings of the 11th ACM SIGPLAN International Conference on Functional Programming, ICFP 2006, Portland, Oregon, USA, September 16–21, 2006, Reppy, J. H. & Lawall, J. L. (eds), ACM Press, pp. 5061.Google Scholar
Schrijvers, T., Peyton Jones, S., Sulzmann, M. & Vytiniotis, D. (2008) Type checking with open type functions. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming, ICFP 2008, Victoria, BC, Canada, September 22–24, 2008, Hook, J. & Thiemann, P. (eds), ACM Press, pp. 5162.Google Scholar
Sheard, T. (2001). Generic unification via two-level types and parameterized modules. In Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming (ICFP '01), Florence, Italy, September 3–5, 2001. ACM Press, pp. 8697.Google Scholar
Sheard, T. & Peyton Jones, S. (2002) Template meta-programming for Haskell. In Proceedings of the ACM SIGPLAN Workshop on Haskell, Pittsburgh, Pennsylvania, 2002. ACM Press, pp. 116.Google Scholar
Xi, H., Chen, C. & Chen, G. (2003) Guarded recursive datatype constructors. In Conference Record of POPL 2003: The 30th SIGPLAN-SIGACT Symposium on Principles of Programming Languages, New Orleans, Louisiana, January 15–17, 2003. ACM Press, pp. 224235.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.