skip to main content
10.1145/1094811.1094814acmconferencesArticle/Chapter ViewAbstractPublication PagessplashConference Proceedingsconference-collections
Article

Generalized algebraic data types and object-oriented programming

Published:12 October 2005Publication History

ABSTRACT

Generalized algebraic data types (GADTs) have received much attention recently in the functional programming community. They generalize the (type) parameterized algebraic datatypes (PADTs) of ML and Haskell by permitting value constructors to return specific, rather than parametric, type-instantiations of their own datatype. GADTs have a number of applications, including strongly-typed evaluators, generic pretty-printing, generic traversals and queries, and typed LR parsing. We show that existing object-oriented programming languages such as Java and C# can express GADT definitions, and a large class of GADT-manipulating programs, through the use of generics, subclassing, and virtual dispatch. However, some programs can be written only through the use of redundant runtime casts. Moreover, instantiation-specific, yet safe, operations on ordinary PADTs only admit indirect cast-free implementations, via higher-order encodings. We propose a generalization of the type constraint mechanisms of C# and Java to both avoid the need for casts in GADT programs and higher-order contortions in PADT programs; we present a Visitor pattern for GADTs, and describe a refined switch construct as an alternative to virtual dispatch on datatypes. We formalize both extensions and prove type soundness.

References

  1. F. Baader and T. Nipkow. Term Rewriting and All That. Cambridge University Press, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. K. B. Bruce, L. Cardelli, G. Castagna, J. Eifrig, S. F. Smith, V. Trifonov, G. T. Leavens, and B. C. Pierce. On binary methods. Theory and Practice of Object Systems, 1(3):221--242, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. J. Cheney and R. Hinze. First-class phantom types. Technical Report 1901, Cornell University, 2003.Google ScholarGoogle Scholar
  4. T. Coquand. Pattern matching with dependent types. In Proceedings of the 1992 Workshop on Types for Proofs and Programs, 1992.Google ScholarGoogle Scholar
  5. K. Crary, S. Weirich, and G. Morrisett. Intensional polymorphism in type erasure semantics. In Journal of Functional Programming, November 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley Professional Computing Series. Addison-Wesley Publishing Company, New York, NY, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. A. Hejlsberg, S. Wiltamuth, and P. Golde. C# version 2.0 specification, 2005. Available from http://msdn.microsoft.com/vcsharp/team/language/default.aspx.Google ScholarGoogle Scholar
  8. R. Hinze. Fun with phantom types. In J. Gibbons and O. de Moor, editors, The Fun of Programming, pages 245--262. Palgrave Macmillan, Mar. 2003.Google ScholarGoogle ScholarCross RefCross Ref
  9. A. Igarashi, B. Pierce, and P. Wadler. Featherweight Java: A minimal core calculus for Java and GJ. In Conference on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. A. Kennedy and D. Syme. Transposing F to C#: Expressivity of parametric polymorphism in an object-oriented language. Concurrency and Computation: Practice and Experience, 16:707--733, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. A. J. Kennedy and D. Syme. Design and implementation of generics for the .NET Common Language Runtime. In Programming Language Design and Implementation. ACM, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. E. Meijer, November 2004. Presentation to IFIP WG 2.8 (private communication).Google ScholarGoogle Scholar
  13. M. Odersky, P. Altherr, V. Cremet, B. Emir, S. Micheloud, N. Mihaylov, M. Schinz, E. Stenman, and M. Zenger. The Scala language specification, 2005. Available from http://scala.epfl.ch/.Google ScholarGoogle Scholar
  14. M. Odersky and P. Wadler. Pizza into Java: Translating Theory into Practice. In 24th ACM Symposium on Principles of Programming Languages (POPL), pages 146--159, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. C. Paulin-Mohring. Inductive definitions in the system Coq: Rules and properties. Technical Report 92-49, Laboratoire de l'Informatique du Parallélisme, Ecole Normale Supérieure de Lyon, December 1992.Google ScholarGoogle Scholar
  16. S. Peyton Jones et al. The ghc compiler version 6.4, March 2005. Download at http://haskell.org/ghc.Google ScholarGoogle Scholar
  17. S. Peyton Jones, G. Washburn, and S. Weirich. Wobbly types: type inference for generalised algebraic data types. Draft, July 2004.Google ScholarGoogle Scholar
  18. F. Pottier and N. Gauthier. Polymorphic typed defunctionalization. In Proceedings of the 31st ACM Symposium on Principles of Programming Languages (POPL'04), pages 89--98, Venice, Italy, Jan. 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. P. Sestoft. Representing typed expressions, December 2001. Code sample in http://www.dina.kvl.dk/~sestoft/gcsharp/#expr.Google ScholarGoogle Scholar
  20. P. Sestoft and H. I. Hansen. C# Precisely. MIT Press, October 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. T. Sheard. Languages of the future. In OOPSLA '04: Companion to the 19th annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications, pages 116--119. ACM Press, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. T. Sheard and E. Pasalic. Meta-programming with built-in type equality. In Fourth International Workshop on Logical Frameworks and Meta-languages (LFM'04), July 2004.Google ScholarGoogle Scholar
  23. V. Simonet and F. Pottier. Constraint-based type inference for guarded algebraic data types. Research Report 5462, INRIA, Jan. 2005.Google ScholarGoogle Scholar
  24. S. Weirich. Type-checker to generate typed term from untyped source, September 2004. Response to challenge at Dagstuhl'04 set by Lennart Augustsson. In ghc regression suite (tc.hs).Google ScholarGoogle Scholar
  25. H. Xi, C. Chen, and G. Chen. Guarded recursive datatype constructors. In POPL '03: Proceedings of the 30th ACM SIGPLAN-SIGACT symposium on Principles of Programming Languages, pages 224--235. ACM Press, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. M. Zenger and M. Odersky. Extensible algebraic datatypes with defaults. In ICFP '01: Proceedings of the 6th ACM International Conference on Functional Programming, pages 241--252. ACM Press, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Generalized algebraic data types and object-oriented programming

                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
                • Published in

                  cover image ACM Conferences
                  OOPSLA '05: Proceedings of the 20th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications
                  October 2005
                  562 pages
                  ISBN:1595930310
                  DOI:10.1145/1094811
                  • cover image ACM SIGPLAN Notices
                    ACM SIGPLAN Notices  Volume 40, Issue 10
                    Proceedings of the 20th annual ACM SIGPLAN conference on Object oriented programming systems languages and applications
                    October 2005
                    531 pages
                    ISSN:0362-1340
                    EISSN:1558-1160
                    DOI:10.1145/1103845
                    Issue’s Table of Contents

                  Copyright © 2005 ACM

                  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]

                  Publisher

                  Association for Computing Machinery

                  New York, NY, United States

                  Publication History

                  • Published: 12 October 2005

                  Permissions

                  Request permissions about this article.

                  Request Permissions

                  Check for updates

                  Qualifiers

                  • Article

                  Acceptance Rates

                  Overall Acceptance Rate268of1,244submissions,22%

                  Upcoming Conference

                PDF Format

                View or Download as a PDF file.

                PDF

                eReader

                View online with eReader.

                eReader