skip to main content
10.1145/1328438.1328475acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
research-article

Foundations for structured programming with GADTs

Published:07 January 2008Publication History

ABSTRACT

GADTs are at the cutting edge of functional programming and becomemore widely used every day. Nevertheless, the semantic foundations underlying GADTs are not well understood. In this paper we solve this problem by showing that the standard theory of data types as carriers of initial algebras of functors can be extended from algebraic and nested data types to GADTs. We then use this observation to derivean initial algebra semantics for GADTs, thus ensuring that all of the accumulated knowledge about initial algebras can be brought to bear on them. Next, we use our initial algebra semantics for GADTs to derive expressive and principled tools --- analogous to the well-known and widely-used ones for algebraic and nested data types---for reasoning about, programming with, and improving the performance of programs involving, GADTs; we christen such a collection of tools for a GADT an initial algebra package. Along the way, we give a constructive demonstration that every GADT can be reduced to one which uses only the equality GADT and existential quantification. Although other such reductions exist in the literature, ours is entirely local, is independent of any particular syntactic presentation of GADTs, and can be implemented in the host language, rather than existing solely as a metatheoretical artifact. The main technical ideas underlying our approach are (i) to modify the notion of a higher-order functor so that GADTs can be seen as carriers of initial algebras of higher-order functors, and (ii) to use left Kan extensions to trade arbitrary GADTs for simpler-but-equivalent ones for which initial algebra semantics can bederived.

References

  1. E. S. Bainbridge, P. J. Freyd, A. Scedrov and P. J. Scott. Functorial polymorphism. Theoretical Computer Science 70(1) (1990), pp. 35--64. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. I. Bayley. Generic Operations on Nested Datatypes. Ph.D. Dissertation, Univ. of Oxford, 2001. At http://web.comlab.ox.ac.uk/oucl/research/areas/ap/papers/bayley-thesis.pdfGoogle ScholarGoogle Scholar
  3. P. Blampied. Structured Recursion for Non-uniform Data-types. Ph.D. Dissertation, Univ. of Nottingham, 2000. At http://www.cs.nott.ac.uk/Research/fop/blampied-thesis.pdfGoogle ScholarGoogle Scholar
  4. Bird, R. and Meertens, L. Nested datatypes. Proc., Mathematics of Program Construction, pp. 52--67, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. R. Bird and R. Paterson. de Bruijn notation as a nested datatype. Journal of Functional Programming 9(1) (1998), pp. 77--91. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. R. Bird and R. Paterson. Generalised folds for nested datatypes. Formal Aspects of Computing 11(2) (1999), pp. 200--222.Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. J. Cheney and R. Hinze. First-class phantom types. At http://www.informatik.uni-bonn.de/~ralf/publications/Phantom.pdfGoogle ScholarGoogle Scholar
  8. P. Dybjer. Inductive Families. Formal Aspects of Computing 6(4), pp. 440--465, 1994.Google ScholarGoogle ScholarCross RefCross Ref
  9. A. Gill, J. Launchbury, and S. L. Peyton Jones. A short cut to deforestation. Proceedings, Functional Programming Languages and Computer Architecture, pp. 223--232, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. N. Ghani, P. Johann, T. Uustalu, and V. Vene. Monadic augment and generalised short cut fusion. Proceedings, International Conference on Functional Programming, pp. 294--305, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. N. Ghani, T. Uustalu, and V. Vene. Build, augment and destroy. Universally. Proceedings, Asian Symposium on Programming Languages, pp. 327--347, 2003.Google ScholarGoogle Scholar
  12. P. Johann and N. Ghani. Initial algebra semantics is enough! Proceedings, Typed Lambda Calculus and Applications, pp. 207--222, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. P. Johann and N. Ghani. Programming with Nested Types. Submitted, 2007.Google ScholarGoogle Scholar
  14. P. Johann. A generalization of short-cut fusion and its correctness proof. Higher-order and Symbolic Computation 15 (2002), pp. 273--300. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. MacLane, S. Categories for the Working Mathematician. Springer-Verlag, 1971.Google ScholarGoogle Scholar
  16. C. Martin, J. Gibbons, and I. Bayley. Disciplined efficient generalised folds for nested datatypes. Formal Aspects of Computing 16(1) (2004), pp. 19--35. Google ScholarGoogle ScholarCross RefCross Ref
  17. C. McBride. Epigram: Practical programming with dependent types. Proceedings, 5th International Summer School on Advanced Functional Programming, 2004. At http://www.e-pig.org/downloads/epigram-notes.pdf Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. The Omega Download Page. http://web.cecs.pdx.edu/~sheard/Omega/index.htmlGoogle ScholarGoogle Scholar
  19. F. Pfenning and C. Paulin-Mohring. Inductively defined types in the Calculus of Constructions. Proceedings, Mathematical Foundations of Programming Semantics, pp. 209--228, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. T. Sheard, J. Hook, and N Linger. GADTs + extensible kinds = dependent programming. At http://www.cs.pdx.edu/~sheard/papers/GADT+ExtKinds.psGoogle ScholarGoogle Scholar
  21. T. Sheard and E. Pasalic. Meta-programming with built-in type equality. Proceedings, Logical Frameworks and Meta-languages, 2004. At http://homepage.mac.com/pasalic/p2/papers/LFM04.pdfGoogle ScholarGoogle Scholar
  22. M. Sulzmann and M. Wang. A systematic translation of guarded recursive data types to existential types. At http://www.comp.nus.edu.sg/~sulzmann/research/ms.htmlGoogle ScholarGoogle Scholar
  23. M. Sulzmann and M. Wang. Translating generalized algebraic data types to System F. Manuscript, 2005. At http://www.comp.nus.edu.sg/~sulzmann/manuscript/simple-translate-gadts.psGoogle ScholarGoogle Scholar
  24. J. Svenningsson. Shortcut fusion for accumulating parameters & zip-like functions. Proceedings, International Conference on Functional Programming, pp. 124--132, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. A. Takano and E. Meijer. Shortcut deforestation in calculational form. Proceedings, Functional Programming Languages and Computer Architecture, pp. 306--313, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. H. Xi, C. Chen, and G. Chen. Guarded recursive datatype constructors. Proceedings, Principles of Programming Languages, pp. 224--235, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. H. Xi and F. Pfenning. Dependent types in practical programming. Proceedings, Principles of Programming Languages, p. 214--227, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Foundations for structured programming with GADTs

    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

    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!