skip to main content
research-article

Shared subtypes: subtyping recursive parametrized algebraic data types

Published:25 September 2008Publication History
Skip Abstract Section

Abstract

A newtype declaration in Haskell introduces a new type renaming an existing type. The two types are viewed by the programmer as semantically different, but share the same runtime representation. When operations on the two semantic views coincide, the run-time cost of conversion between the two types is reduced to zero (in both directions) because of this common representation.

We describe a new language feature called Shared Subtypes (SSubtypes), which generalizes these properties of the newtype declaration. SSubtypes allow programmers to specify subtype rules between types and sharing rules between data constructors. A value of a type T, where T is a subtype of U, can always be cast, at no cost, to value of type U. This free up-casting allows library functions that consume the supertype to be applied without cost to subtypes. Yet any semantic interpretations desired by the programmer can be enforced by the compiler. SSubtype declarations work particularly well with GADTs. GADTs use differing type indexes to make explicit semantic differences, by using a different index for each way of viewing the data. Shared subtypes allow GADTs to share the same runtime representation as a reference type, of which the GADT is a refinement.

Skip Supplemental Material Section

Supplemental Material

Video

References

  1. Roberto M. Amadio and Luca Cardelli. Subtyping recursive types. ACM Transactions on Programming Languages and Systems, 15(4):575--631, September 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Peter S. Canning, William Cook, Walter L. Hill, John C. Mitchell, and Walter G. Olthoff. F-bounded polymorphism for object-oriented programming. In Proceedings of the ACM Conference on Functional Programming and Computer Architecture, pages 273--280, September 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Luca Cardelli. A semantics of multiple inheritance. In Proceedings of the International Symposium on the Semantics of Data Types, volume 173 of LNCS, pages 51--67, 1984. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. T. Freeman and F. Pfenning. Refinement types for ML. In PLDI'91, volume 26, pages 268--277, June 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Jacques Garrigue. Programming with polymorphic variants. In ML Workshop. 1998.Google ScholarGoogle Scholar
  6. The GHC Team. The glorious Glasgow Haskell Compilation system user's guide, version 6.8.2. Section 8.4.6, 2008.Google ScholarGoogle Scholar
  7. Mark P. Jones. Qualified Types: Theory and Practice. CUP, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Koji Kagawa. Polymorphic variants in haskell. In Haskell'06, pages 37--47. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Alexandre Miquel. In TLCA'01, volume 2044, pages 344--359. Springer-Verlag, May 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Johan Nordlander. Polymorphic subtyping in O'Haskell. Science of Computer Programming, 43(2-3):93--127, June 2002. ISSN 0167-6423.Google ScholarGoogle ScholarCross RefCross Ref
  11. Johan Nordlander. Pragmatic subtyping in polymorphic languages. In ICFP'98, pages 216--227, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Simon Peyton Jones et al., editors. Haskell 98 Language and Libraries, the Revised Report. Cambridge University Press, 2003.Google ScholarGoogle Scholar
  13. Benjamin C. Pierce. Types and Programming Languages. MIT Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Tim Sheard. Languages of the future. In OOPSLA Companion, pages 116--119. ACM, 2004. ISBN 1-58113-833-4. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. D. Syme, A. Granicz, and A. Cisternino. Expert F#. Springer, 2007.Google ScholarGoogle ScholarCross RefCross Ref
  16. Robert E. Tarjan. Depth first search and linear graph algorithms. SIAM J. Computing, 1(2):146--160, 1972.Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. Shared subtypes: subtyping recursive parametrized algebraic data types

        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

        Full Access

        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!