skip to main content
article

A pattern for almost compositional functions

Authors Info & Claims
Published:16 September 2006Publication History
Skip Abstract Section

Abstract

This paper introduces a pattern for almost compositional functions over recursive data types, and over families of mutually recursive data types. Here "almost compositional" means that for a number of the constructors in the type(s), the result of the function depends only on the constructor and the results of calling the function on the constructor's arguments. The pattern consists of a generic part constructed once for each data type or family of data types, and a task-specific part. The generic part contains the code for the predictable compositional cases, leaving the interesting work to the task-specific part. Examples of the pattern implemented in dependent type theory with inductive families, in Haskell with generalized algebraic data types and rank-2 polymorphism, and in Java using a variant of the Visitor design pattern are given. The relationship to the "Scrap Your Boilerplate" approach to generic programming, and to general tree types in dependent type theory are also investigated.

References

  1. ALEXANDRESCU, A. Modern C++ Design: Generic Programming and Design Patterns Applied. Addison-Wesley Professional, Feb. 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. APPEL, A. W. Modern Compiler Implementation in ML. Cambridge University Press, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. APPEL, A. W. Modern Compiler Implementation in Java, second ed. Cambridge University Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. BRINGERT, B. The Transfer programming language. http://www.cs.chalmers.se/.~aarne/GF/doc/transfer.html.Google ScholarGoogle Scholar
  5. COQUAND, C. The Agda homepage. http://www.cs.chalmers.se/~catarina/agda/.Google ScholarGoogle Scholar
  6. FORSBERG, M., AND RANTA, A. BNF Converter homepage. http://www.cs.chalmers.se/.markus/BNFC/.Google ScholarGoogle Scholar
  7. GAMMA, E., HELM, R., JOHNSON, R., AND VLISSIDES, J. Design Patterns: Elements of Reusable Object-Oriented Software. Addison- Wesley, Reading, Massachusetts, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. HINZE, R. Generics for the masses. In ICFP '04: Proceedings of the ninth ACM SIGPLAN international conference on Functional programming (New York, NY, USA, 2004), ACM Press, pp. 236--243. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. HINZE, R., LÖH, A., AND OLIVEIRA, B. C. D. S. "ScrapYour Boilerplate" reloaded. In FLOPS (2006), M. Hagiya and P. Wadler, Eds., vol. 3945 of Lecture Notes in Computer Science, Springer, pp. 13--29. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. JANSSON, P., AND JEURING, J. PolyP - a polytypic programming language extension. In POPL '97: The 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (1997), ACM Press, pp. 470--482. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. JONES, M. P. Functional programming with overloading and higher-order polymorphism. In Advanced Functional Programming, First International Spring School on Advanced Functional Programming Techniques-Tutorial Text (London, UK, 1995), Springer-Verlag, pp. 97--136. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. JONES, S. P. The Haskell 98 language. Journal of Functional Programming 13,1 (2003).Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. JONES, S. P., VYTINIOTIS, D., WEIRICH, S., AND WASHBURN, G. Simple unification-based type inference for GADTs. Submitted to ICFP'06. http://research. microsoft.com/Users/simonpj/papers/gadt/,Apr. 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. LÄMMEL, R., AND PEYTON JONES, S. Scrap your boilerplate:a practical design pattern for generic programming. ACM SIGPLAN Notices 38, 3 (Mar. 2003), 26--37. Proceedings of the ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI 2003). Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. LEE, L.-Q., LUMSDAINE, A., AND SIEK, J. G. The Boost graph library: user guide and reference manual. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. MCBRIDE, C., AND PATERSON, R. Applicative programming with effects. Submitted to Journal of Functional Programming. http://www.soi.city.ac.uk/~ross/papers/Applicative.pdf. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. PELLAUER, M., FORSBERG, M., AND RANTA, A. BNFConverter: Multilingual front-end generation from labelled BNF. Tech. Rep. 2004-09, Department of Computing Science, Chalmers University of Technology and Göteborg University, 2004. http://www. cs.chalmers.se/~markus/tech2004.pdf.Google ScholarGoogle Scholar
  18. PETERSSON, K., AND SYNEK, D. A set constructor for inductive sets in Martin-Löf's type theory. In Category Theory and Computer Science (1989), pp. 128--140. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. RANTA, A. Grammatical Framework, a type-theoretical grammar formalism. The Journal of Functional Programming 14,2 (2004), 145--189. http://www. cs. chalmers. se/~aarne/articles/gf-jfp. ps. gz. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. SHEARD, T., AND PEYTON JONES, S. Template metaprogramming for Haskell. In ACM SIGPLAN Haskell Workshop 02 (Oct. 2002), M. M. T. Chakravarty, Ed., ACM Press, pp. 1--16. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. VISSER, J. Visitor combination and traversal control. In OOPSLA '01: Proceedings of the 16th ACM SIGPLAN conference on Object oriented programming, systems, languages, and applications (New York, NY, USA, 2001), ACM Press, pp. 270--282. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. WINSTANLEY, N., WALLACE, M., AND MEACHAM, J. The DrIFT homepage. http://repetae.net/~john/computer/haskell/DrIFT/.Google ScholarGoogle Scholar

Index Terms

  1. A pattern for almost compositional functions

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 41, Issue 9
        Proceedings of the 2006 ICFP conference
        September 2006
        296 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/1160074
        Issue’s Table of Contents
        • cover image ACM Conferences
          ICFP '06: Proceedings of the eleventh ACM SIGPLAN international conference on Functional programming
          September 2006
          308 pages
          ISBN:1595933093
          DOI:10.1145/1159803
          • General Chair:
          • John Reppy,
          • Program Chair:
          • Julia Lawall

        Copyright © 2006 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 16 September 2006

        Check for updates

        Qualifiers

        • article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!