# Phantom types and subtyping

@article{Fluet2006PhantomTA, title={Phantom types and subtyping}, author={Matthew Fluet and Riccardo Pucella}, journal={Journal of Functional Programming}, year={2006}, volume={16}, pages={751 - 791} }

We investigate a technique from the literature, called the phantom-types technique, that uses parametric polymorphism, type constraints, and unification of polymorphic types to model a subtyping hierarchy. Hindley-Milner type systems, such as the one found in Standard ML, can be used to enforce the subtyping relation, at least for first-order values. We show that this technique can be used to encode any finite subtyping hierarchy (including hierarchies arising from multiple interface… Expand

#### Supplemental Presentations

#### Topics from this paper

#### 49 Citations

Practical Datatype Specializations with Phantom Types and Recursion Schemes

- Computer Science, Mathematics
- Electron. Notes Theor. Comput. Sci.
- 2006

It is shown that it is possible to express statically-checked specializations within the type system of Standard ML in a way that does not lose useful programming facilities such as pattern matching in case expressions. Expand

Sound and complete bidirectional typechecking for higher-rank polymorphism with existentials and indexed types

- Computer Science
- Proc. ACM Program. Lang.
- 2019

This work gives a declarative specification of typing based on focalization, allowing for coverage of pattern matching, as well as support for first-class existential types using a focalized subtyping judgment, and extends the declaratives specification with an explicit rules for deducing when a type is principal. Expand

Thesis Proposal: Unifying Principles of Type Refinements

- 2020

Traditional static type systems in the Hindley-Milner style are a useful means of guaranteeing type safety, in the form of type preservation and progress theorems, and of broadly specifying… Expand

An extensible dynamically-typed hierarchy of exceptions

- Computer Science
- Haskell '06
- 2006

This paper proposes a lightweight solution involving the use of existential types and the Typeable class only, and shows how this solution allows a fully extensible hierarchy of exception types to be declared, in which a single overloaded catch operator can be used to catch either specific exception types, or exceptions belonging to any subclass in the hierarchy. Expand

A unified system of type refinements

- Computer Science
- 2007

This work presents a system of type refinements that unifies and extends past work on datasort and index refinements, and provides unified mechanisms of definite types, such as intersections, and indefinite types,such as unions. Expand

Sound and Complete Bidirectional Typechecking for Higher-Rank Polymorphism with Existentials

- 2018

ANONYMOUS AUTHOR(S) Bidirectional typechecking, in which terms either synthesize a type or are checked against a known type, has become popular for its scalability, its error reporting, and its ease… Expand

Dotty Phantom Types

- 2020

Phantom types are a well-known type-level, design pattern which is commonly used to express constraints encoded in types. We observe that in modern, multi-paradigm programming languages, these… Expand

Sound and Complete Bidirectional Typechecking for Higher-Rank Polymorphism with Existentials and Indexed Types ANONYMOUS

- 2018

ANONYMOUS AUTHOR(S) Bidirectional typechecking, in which terms either synthesize a type or are checked against a known type, has become popular for its scalability, its error reporting, and its ease… Expand

Lightweight Static Capabilities

- Computer Science
- Electron. Notes Theor. Comput. Sci.
- 2007

A modular programming style that harnesses modern type systems to verify safety conditions in practical systems and calls for an expressive core language, higher-rank polymorphism, and phantom types is described. Expand

Translating dependency into parametricity

- Computer Science
- ICFP '04
- 2004

It is proved that the parametricity theorem for F implies the noninterference theorem for DCC, and the translation provides insights into DCC's type system and suggests implementation strategies of dependency calculi in polymorphic languages. Expand

#### References

SHOWING 1-10 OF 23 REFERENCES

An Extension of System F with Subtyping

- Computer Science
- TACS
- 1991

The main focus of the paper is the equational theory of F<:, which is related to PER models and the notion of parametricity, and some categorical properties of the theory when restricted to closed terms, including interesting categorical isomorphisms. Expand

Practical Datatype Specializations with Phantom Types and Recursion Schemes

- Computer Science, Mathematics
- Electron. Notes Theor. Comput. Sci.
- 2006

It is shown that it is possible to express statically-checked specializations within the type system of Standard ML in a way that does not lose useful programming facilities such as pattern matching in case expressions. Expand

A Theory of Type Polymorphism in Programming

- Computer Science
- J. Comput. Syst. Sci.
- 1978

This work presents a formal type discipline for polymorphic procedures in the context of a simple programming language, and a compile time type-checking algorithm w which enforces the discipline. Expand

Type inference with polymorphic recursion

- Computer Science
- TOPL
- 1993

The Damas-Milner Calculus is the typed λ-calculus underlying the type system for ML and several other strongly typed polymorphic functional languages such as Miranda and Haskell. Mycroft has extended… Expand

Refinement types for ML

- Computer Science
- PLDI '91
- 1991

A type system called refinement types is described, which is an example of a new way to make this tradeoff, as well as a potentially useful system in itself. Expand

Type reconstruction in the presence of polymorphic recursion

- Computer Science
- TOPL
- 1993

It is shown that the typability problem for each one of these extensions of ML is polynomial-time equivalent to the Semi-Unification Problem and, therefore, undecidable. Expand

Type extension through polymorphism

- Computer Science
- TOPL
- 1990

A record data type can be extended by addition of more fields, which results in a type hierarchy that can be used in Ada and other languages with generic program units. Expand

No-Longer-Foreign: Teaching an ML compiler to speak C "natively"

- Computer Science
- Electron. Notes Theor. Comput. Sci.
- 2001

The core component of this work is an encoding of the almost 2 complete C type system in ML types, taking advantage of ML’s polymorphism, its type constructors, its abstraction mechanisms, and even functors. Expand

Type checking records and variants in a natural extension of ML

- Computer Science
- POPL '89
- 1989

This work solves the problem of global treatment of record types as a special case by giving an ordinary status to records without any ad hoc assertions, replacing inclusion rules by extra information in record types. Expand

Semantics, Applications, and Implementation of Program Generation

- Computer Science
- Lecture Notes in Computer Science
- 2001

A Transformational Approach which Combines Size Inference and Program Optimization is presented, which combines size inference and program Optimization. Expand