CJO - Abstract - A pattern for almost compositional functions

Cambridge Journals Online

Cambridge Journals Online
Journal of Functional Programming (2008), 18 : 567-598 Cambridge University Press
doi:10.1017/S0956796808006898 (About doi)
Published online by Cambridge University Press 02 Sep 2008
Cambridge Journals Online - CUP Full-Text Page
Journal of Functional Programming (2008), 18:567-598 Cambridge University Press
Copyright © Cambridge University Press 2008
doi:10.1017/S0956796808006898

Articles

A pattern for almost compositional functions


BJÖRN BRINGERTa1 and AARNE RANTAa1

a1 Department of Computer Science and Engineering, Chalmers University of Technology and University of Gothenburg SE-412 96, Göteborg, Sweden (e-mail: bringert@chalmers.se, aarne@chalmers.se)
Article author query
bringert b Google Scholar
ranta a Google Scholar

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 all of the constructors in the type(s), except a limited number of them, 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 are given, 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. The relationships to the “Scrap Your Boilerplate” approach to generic programming, and to general tree types in dependent type theory, are investigated by reimplementing our operations using those frameworks.


Cambridge University Press