skip to main content
10.1145/2036918.2036930acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Compositional data types

Published: 18 September 2011 Publication History

Abstract

Building on Wouter Swierstra's Data types à la carte, we present a comprehensive Haskell library of compositional data types suitable for practical applications. In this framework, data types and functions on them can be defined in a modular fashion. We extend the existing work by implementing a wide array of recursion schemes including monadic computations. Above all, we generalise recursive data types to contexts, which allow us to characterise a special yet frequent kind of catamorphisms. The thus established notion of term homomorphisms allows for flexible reuse and enables short-cut fusion style deforestation which yields considerable speedups. We demonstrate our framework in the setting of compiler construction, and moreover, we compare compositional data types with generic programming techniques and show that both are comparable in run-time performance and expressivity while our approach allows for stricter types. We substantiate this conclusion by lifting compositional data types to recursive data types and generalised algebraic data types. Lastly, we compare the run-time performance of our techniques with traditional implementations over algebraic data types. The results are surprisingly good.

Supplementary Material

JPG File (_talk9.jpg)
MP4 File (_talk9.mp4)

References

[1]
R. Bird and R. Paterson. Generalised folds for nested datatypes. Formal Aspects of Computing, 11 (2): 200--222, 1999.
[2]
H. Comon, M. Dauchet, R. Gilleron, C. Löding, F. Jacquemard, D. Lugiez, S. Tison, and M. Tommasi. Tree Automata Techniques and Applications. 2007. Draft.
[3]
M. Fokkinga. Monadic Maps and Folds for Arbitrary Datatypes. Technical report, Memoranda Informatica, University of Twente, 1994.
[4]
A. Gill, J. Launchbury, and S. L. Peyton Jones. A short cut to deforestation. In FPCA '93, pages 223--232. ACM, 1993.
[5]
I. Hasuo, B. Jacobs, and T. Uustalu. Categorical Views on Computations on Trees (Extended Abstract). In L. Arge, C. Cachin, T. Jurdzinski, and A. Tarlecki, editors, Automata, Languages and Programming, volume 4596 of LNCS, pages 619--630. Springer, 2007.
[6]
P. Johann and N. Ghani. Foundations for structured programming with GADTs. In POPL '08, pages 297--308. ACM, 2008.
[7]
S. Jones, A. Tolmach, and T. Hoare. Playing by the rules: rewriting as a practical optimisation technique in GHC. In Haskell Workshop '01, pages 203--233, 2001.
[8]
G. Malcolm. Data structures and program transformation. Science of Computer Programming, 14 (2-3): 255 -- 279, 1990.
[9]
S. Marlow. Haskell 2010 Language Report, 2010.
[10]
C. McBride and R. Paterson. Applicative programming with effects. Journal of Functional Programming, 18 (01): 1--13, 2008.
[11]
E. Meijer, M. Fokkinga, and R. Paterson. Functional programming with bananas, lenses, envelopes and barbed wire. In FPCA '91, pages 124--144. ACM, 1991.
[12]
N. Mitchell and C. Runciman. Uniform boilerplate and list processing. In Haskell Workshop '07, pages 49--60. ACM, 2007.
[13]
J. G. Morris and M. P. Jones. Instance chains: type class programming without overlapping instances. In ICFP '10, pages 375--386, 2010.
[14]
Rodriguez Yakushev, Jeuring, Jansson, Gerdes, Kiselyov, and Oliveira}rodriguez08haskellA. Rodriguez Yakushev, J. Jeuring, P. Jansson, A. Gerdes, O. Kiselyov, and B. C. d. S. Oliveira. Comparing libraries for generic programming in Haskell. In Haskell Workshop '08, pages 111--122. ACM, 2008.
[15]
A. Rodriguez Yakushev, J. Jeuring, P. Jansson, A. Gerdes, O. Kiselyov, and B. C. d. S. Oliveira. Comparing libraries for generic programming in Haskell. Technical report, Department of Information and Computing Sciences, Utrecht University, 2008.
[16]
A. Rodriguez Yakushev, S. Holdermans, A. Löh, and J. Jeuring. Generic programming with fixed points for mutually recursive datatypes. In ICFP '09, pages 233--244. ACM, 2009.
[17]
T. Schrijvers, S. Peyton Jones, M. Sulzmann, and D. Vytiniotis. Complete and decidable type inference for GADTs. In ICFP '09, pages 341--352. ACM, 2009.
[18]
T. Sheard and S. P. Jones. Template meta-programming for Haskell. In Haskell Workshop '02, pages 1--16. ACM, 2002.
[19]
S. Swierstra, P. Azero Alcocer, and J. Saraiva. Designing and implementing combinator languages. In S. Swierstra, J. Oliveira, and P. Henriques, editors, Advanced Functional Programming, volume 1608 of LNCS, pages 150--206. Springer, 1999.
[20]
W. Swierstra. Data types à la carte. Journal of Functional Programming, 18 (4): 423--436, 2008.
[21]
J. W. Thatcher. Tree automata: an informal survey, chapter 4, pages 143--178. Prentice Hall, 1973.
[22]
M. Van Steenbergen, J. P. Magalhaes, and J. Jeuring. Generic selections of subexpressions. In WGP '10, pages 37--48. ACM, 2010.
[23]
V. Vene. Categorical programming with inductive and coinductive types. Phd thesis, University of Tartu, Estonia, 2000.
[24]
S. Visser and A. Löh. Generic storage in Haskell. In WGP '10, pages 25--36. ACM, 2010.
[25]
P. Wadler. The Expression Problem. http://homepages.inf.ed.ac.uk/wadler/papers/ expression/expression.txt, 1998.
[26]
B. Yorgey. Typed type-level functional programming in GHC. Talk at Haskell Implementors Workshop, 2010.

Cited By

View all
  • (2023)Towards a Language for Defining Reusable Programming Language ComponentsTrends in Functional Programming10.1007/978-3-031-21314-4_2(18-38)Online publication date: 1-Jan-2023
  • (2022)iCoLa: A Compositional Meta-language with Support for Incremental Language DevelopmentProceedings of the 15th ACM SIGPLAN International Conference on Software Language Engineering10.1145/3567512.3567529(202-215)Online publication date: 29-Nov-2022
  • (2022)Flexible presentations of graded monadsProceedings of the ACM on Programming Languages10.1145/35476546:ICFP(902-930)Online publication date: 31-Aug-2022
  • Show More Cited By

Recommendations

Reviews

Jacques Carette

Modularity and extensibility are continuing concerns, and different programming paradigms have an effect on this: object-oriented and functional languages make it easy to add new data representations and new functions (respectively) to old data representations. This is the well-known expression problem. While there are many solutions to it, none can yet claim to be "the" solution (if there even is such a thing). The authors present compositional data types, an extension of Swierstra's data types ? la carte [1]. They then go far beyond to include more general recursion schemes, add generic programming, and show that the results are reasonably efficient. They show how to deal with mutually recursive types and generalized algebraic data types (GADTs), and also make the claim, with some supporting evidence, that this method is practical; on this last aspect, time will tell. The work is supported as well as guided by a lot of theory on data types, which is generally founded on a categorical formalism. This is comforting for experts and daunting for beginners. Whenever these advanced foundations leak into user space (as they often do in error messages), any claims that this is a practical solution become dubious. However, in theory, this is a very nice solution indeed. Written for domain experts, the paper is (for its audience) very well written. The problem and its solution are well motivated and carefully explained. The full code behind this work is also published on Hackage (http://hackage.haskell.org/package/compdata). The main drawback of this paper is that, at times, the authors stick too closely to Haskell details-for example, not noticing in section 4.1 that they are trying to perform a little bit of intensional analysis on terms. The use of contexts is a clever way to tame unbounded intensionality, but contexts otherwise appear here as an ad hoc solution even though they are not. Similarly, the link with universal algebra (or its categorical brethren), especially in section 4.3, would have been a welcome addition. Nevertheless, any expert in the data type generic programming domain should read this paper. Online Computing Reviews Service

Access critical reviews of Computing literature here

Become a reviewer for Computing Reviews.

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
WGP '11: Proceedings of the seventh ACM SIGPLAN workshop on Generic programming
September 2011
102 pages
ISBN:9781450308618
DOI:10.1145/2036918
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 18 September 2011

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. algebraic programming
  2. deforestation
  3. mutual recursion
  4. reusability

Qualifiers

  • Research-article

Conference

ICFP '11
Sponsor:

Acceptance Rates

WGP '11 Paper Acceptance Rate 8 of 10 submissions, 80%;
Overall Acceptance Rate 30 of 43 submissions, 70%

Upcoming Conference

ICFP '25
ACM SIGPLAN International Conference on Functional Programming
October 12 - 18, 2025
Singapore , Singapore

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)27
  • Downloads (Last 6 weeks)5
Reflects downloads up to 05 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2023)Towards a Language for Defining Reusable Programming Language ComponentsTrends in Functional Programming10.1007/978-3-031-21314-4_2(18-38)Online publication date: 1-Jan-2023
  • (2022)iCoLa: A Compositional Meta-language with Support for Incremental Language DevelopmentProceedings of the 15th ACM SIGPLAN International Conference on Software Language Engineering10.1145/3567512.3567529(202-215)Online publication date: 29-Nov-2022
  • (2022)Flexible presentations of graded monadsProceedings of the ACM on Programming Languages10.1145/35476546:ICFP(902-930)Online publication date: 31-Aug-2022
  • (2022)Random testing of a higher-order blockchain language (experience report)Proceedings of the ACM on Programming Languages10.1145/35476536:ICFP(886-901)Online publication date: 31-Aug-2022
  • (2022)Fusing industry and academia at GitHub (experience report)Proceedings of the ACM on Programming Languages10.1145/35476396:ICFP(496-511)Online publication date: 31-Aug-2022
  • (2022)Reference counting with frame limited reuseProceedings of the ACM on Programming Languages10.1145/35476346:ICFP(357-380)Online publication date: 31-Aug-2022
  • (2022)Program adverbs and Tlön embeddingsProceedings of the ACM on Programming Languages10.1145/35476326:ICFP(312-342)Online publication date: 31-Aug-2022
  • (2022)Later credits: resourceful reasoning for the later modalityProceedings of the ACM on Programming Languages10.1145/35476316:ICFP(283-311)Online publication date: 31-Aug-2022
  • (2020)Pattern matching in an open worldACM SIGPLAN Notices10.1145/3393934.327812453:9(134-146)Online publication date: 7-Apr-2020
  • (2020)Castor: Programming with extensible generative visitorsScience of Computer Programming10.1016/j.scico.2020.102449(102449)Online publication date: Mar-2020
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media