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.
- ALEXANDRESCU, A. Modern C++ Design: Generic Programming and Design Patterns Applied. Addison-Wesley Professional, Feb. 2001. Google Scholar
Digital Library
- APPEL, A. W. Modern Compiler Implementation in ML. Cambridge University Press, 1998. Google Scholar
Digital Library
- APPEL, A. W. Modern Compiler Implementation in Java, second ed. Cambridge University Press, 2002. Google Scholar
Digital Library
- BRINGERT, B. The Transfer programming language. http://www.cs.chalmers.se/.~aarne/GF/doc/transfer.html.Google Scholar
- COQUAND, C. The Agda homepage. http://www.cs.chalmers.se/~catarina/agda/.Google Scholar
- FORSBERG, M., AND RANTA, A. BNF Converter homepage. http://www.cs.chalmers.se/.markus/BNFC/.Google Scholar
- GAMMA, E., HELM, R., JOHNSON, R., AND VLISSIDES, J. Design Patterns: Elements of Reusable Object-Oriented Software. Addison- Wesley, Reading, Massachusetts, 1994. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- JONES, S. P. The Haskell 98 language. Journal of Functional Programming 13,1 (2003).Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- WINSTANLEY, N., WALLACE, M., AND MEACHAM, J. The DrIFT homepage. http://repetae.net/~john/computer/haskell/DrIFT/.Google Scholar
Index Terms
A pattern for almost compositional functions
Recommendations
A pattern for almost compositional functions
ICFP '06: Proceedings of the eleventh ACM SIGPLAN international conference on Functional programmingThis 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 ...
A pattern for almost compositional functions
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 all of the constructors in the type(s), except a limited number ...
A relationally parametric model of dependent type theory
POPL '14Reynolds' theory of relational parametricity captures the invariance of polymorphically typed programs under change of data representation. Reynolds' original work exploited the typing discipline of the polymorphically typed lambda-calculus System F, ...







Comments