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.
- E. S. Bainbridge, P. J. Freyd, A. Scedrov and P. J. Scott. Functorial polymorphism. Theoretical Computer Science 70(1) (1990), pp. 35--64. Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- Bird, R. and Meertens, L. Nested datatypes. Proc., Mathematics of Program Construction, pp. 52--67, 1998. Google Scholar
Digital Library
- R. Bird and R. Paterson. de Bruijn notation as a nested datatype. Journal of Functional Programming 9(1) (1998), pp. 77--91. Google Scholar
Digital Library
- R. Bird and R. Paterson. Generalised folds for nested datatypes. Formal Aspects of Computing 11(2) (1999), pp. 200--222.Google Scholar
Digital Library
- J. Cheney and R. Hinze. First-class phantom types. At http://www.informatik.uni-bonn.de/~ralf/publications/Phantom.pdfGoogle Scholar
- P. Dybjer. Inductive Families. Formal Aspects of Computing 6(4), pp. 440--465, 1994.Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- N. Ghani, T. Uustalu, and V. Vene. Build, augment and destroy. Universally. Proceedings, Asian Symposium on Programming Languages, pp. 327--347, 2003.Google Scholar
- P. Johann and N. Ghani. Initial algebra semantics is enough! Proceedings, Typed Lambda Calculus and Applications, pp. 207--222, 2007. Google Scholar
Digital Library
- P. Johann and N. Ghani. Programming with Nested Types. Submitted, 2007.Google Scholar
- P. Johann. A generalization of short-cut fusion and its correctness proof. Higher-order and Symbolic Computation 15 (2002), pp. 273--300. Google Scholar
Digital Library
- MacLane, S. Categories for the Working Mathematician. Springer-Verlag, 1971.Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- The Omega Download Page. http://web.cecs.pdx.edu/~sheard/Omega/index.htmlGoogle Scholar
- 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 Scholar
Digital Library
- T. Sheard, J. Hook, and N Linger. GADTs + extensible kinds = dependent programming. At http://www.cs.pdx.edu/~sheard/papers/GADT+ExtKinds.psGoogle Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- J. Svenningsson. Shortcut fusion for accumulating parameters & zip-like functions. Proceedings, International Conference on Functional Programming, pp. 124--132, 2002. Google Scholar
Digital Library
- A. Takano and E. Meijer. Shortcut deforestation in calculational form. Proceedings, Functional Programming Languages and Computer Architecture, pp. 306--313, 1995. Google Scholar
Digital Library
- H. Xi, C. Chen, and G. Chen. Guarded recursive datatype constructors. Proceedings, Principles of Programming Languages, pp. 224--235, 2003. Google Scholar
Digital Library
- H. Xi and F. Pfenning. Dependent types in practical programming. Proceedings, Principles of Programming Languages, p. 214--227, 1999. Google Scholar
Digital Library
Index Terms
Foundations for structured programming with GADTs
Recommendations
Foundations for structured programming with GADTs
POPL '08GADTs 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 ...
A foundation for GADTs and inductive families: dependent polynomial functor approach
WGP '11: Proceedings of the seventh ACM SIGPLAN workshop on Generic programmingEvery Algebraic Datatype (ADT) is characterised as the initial algebra of a polynomial functor on sets. This paper extends the characterisation to the case of more advanced datatypes: Generalised Algebraic Datatypes (GADTs) and Inductive Families. ...
A Unified Category-theoretic Semantics for Binding Signatures in Substructural Logics
Generalizing Fiore et al.'s use of the category <Fopf> of finite sets to model untyped Cartesian contexts and Tanaka's use of the category <Popf> of permutations to model untyped linear contexts, we let S be an arbitrary pseudo-monad on Cat and let S1 ...







Comments