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.
Supplemental Material
Available for Download
- Roberto M. Amadio and Luca Cardelli. Subtyping recursive types. ACM Transactions on Programming Languages and Systems, 15(4):575--631, September 1993. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- T. Freeman and F. Pfenning. Refinement types for ML. In PLDI'91, volume 26, pages 268--277, June 1991. Google Scholar
Digital Library
- Jacques Garrigue. Programming with polymorphic variants. In ML Workshop. 1998.Google Scholar
- The GHC Team. The glorious Glasgow Haskell Compilation system user's guide, version 6.8.2. Section 8.4.6, 2008.Google Scholar
- Mark P. Jones. Qualified Types: Theory and Practice. CUP, 1994. Google Scholar
Digital Library
- Koji Kagawa. Polymorphic variants in haskell. In Haskell'06, pages 37--47. ACM, 2006. Google Scholar
Digital Library
- Alexandre Miquel. In TLCA'01, volume 2044, pages 344--359. Springer-Verlag, May 2001. Google Scholar
Digital Library
- Johan Nordlander. Polymorphic subtyping in O'Haskell. Science of Computer Programming, 43(2-3):93--127, June 2002. ISSN 0167-6423.Google Scholar
Cross Ref
- Johan Nordlander. Pragmatic subtyping in polymorphic languages. In ICFP'98, pages 216--227, 1998. Google Scholar
Digital Library
- Simon Peyton Jones et al., editors. Haskell 98 Language and Libraries, the Revised Report. Cambridge University Press, 2003.Google Scholar
- Benjamin C. Pierce. Types and Programming Languages. MIT Press, 2002. Google Scholar
Digital Library
- Tim Sheard. Languages of the future. In OOPSLA Companion, pages 116--119. ACM, 2004. ISBN 1-58113-833-4. Google Scholar
Digital Library
- D. Syme, A. Granicz, and A. Cisternino. Expert F#. Springer, 2007.Google Scholar
Cross Ref
- Robert E. Tarjan. Depth first search and linear graph algorithms. SIAM J. Computing, 1(2):146--160, 1972.Google Scholar
Cross Ref
Index Terms
Shared subtypes: subtyping recursive parametrized algebraic data types
Recommendations
Shared subtypes: subtyping recursive parametrized algebraic data types
Haskell '08: Proceedings of the first ACM SIGPLAN symposium on HaskellA 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 ...
System F with coercion constraints
CSL-LICS '14: Proceedings of the Joint Meeting of the Twenty-Third EACSL Annual Conference on Computer Science Logic (CSL) and the Twenty-Ninth Annual ACM/IEEE Symposium on Logic in Computer Science (LICS)We present a second-order λ-calculus with coercion constraints that generalizes a previous extension of System F with parametric coercion abstractions by allowing multiple but simultaneous type and coercion abstractions, as well as recursive coercions ...
Ghostbuster: a tool for simplifying and converting GADTs
ICFP 2016: Proceedings of the 21st ACM SIGPLAN International Conference on Functional ProgrammingGeneralized Algebraic Dataypes, or simply GADTs, can encode non-trivial properties in the types of the constructors. Once such properties are encoded in a datatype, however, all code manipulating that datatype must provide proof that it maintains these ...







Comments