Abstract

Resolution and subtyping are two common mechanisms in programming languages. Resolution is used by features such as type classes or Scala-style implicits to synthesize values automatically from contextual type information. Subtyping is commonly used to automatically convert the type of a value into another compatible type. So far the two mechanisms have been considered independently of each other. This paper shows that, with a small extension, subtyping with intersection types can subsume resolution. This has three main consequences. Firstly, resolution does not need to be implemented as a separate mechanism. Secondly, the interaction between resolution and subtyping becomes apparent. Finally, the integration of resolution into subtyping enables first-class (implicit) environments. The extension that recovers the power of resolution via subtyping is the modus ponens rule of propositional logic. While it is easily added to declarative subtyping, significant care needs to be taken to retain desirable properties, such as transitivity and decidability of algorithmic subtyping, and coherence. To materialize these ideas we develop λiMP, a calculus that extends a iprevious calculus with disjoint intersection types, and develop its metatheory in the Coq theorem prover.

Highlights

  • Subtyping is a well-known programming language feature

  • This paper shows that, with a small extension, subtyping with intersection types can subsume forms of resolution

  • Resolution as subtyping: We extend subtyping of intersection types with modus ponens

Read more

Summary

INTRODUCTION

Subtyping is a well-known programming language feature. It is most notably employed in objectoriented languages, but there are many other uses of subtyping in the literature [Barendregt et al 1983; Chen 2003; Gay and Hole 2005; Pierce and Sangiorgi 1996]. In the case of the application f 3, the input of the function must be Int and the following upcast is triggered in such an application: In Haskell, we may define: class Over a where f :: a -> a instance Over Int where f = succ instance Over Char where f = toUpper This achieves an overloaded behavior similar to the intersection types version of f. This is impossible in existing approaches for type classes and calculi with implicits, as there is no explicit notion of a type for environments To materialize these ideas we develop λiMP: a calculus that extends the NeColus calculus (a calculus with disjoint intersection types [Oliveira et al 2016]) and develop its metatheory in the Coq theorem prover. An extended version of this paper, containing appendices, can be found online, by following this link: https://arxiv.org/abs/2010.06216

BACKGROUND
Different Interpretations for Intersection Types in the Literature
OVERVIEW
Type-Based Overloading with Type Classes
The Merge Operator and Disjoint Intersection Types
First-Class Environments
Technical Challenges
ALGORITHMIC SUBTYPING
The Subtyping Algorithm
COHERENCE
A Context Dependent Logical Relation
Coherence Proof
RELATED WORK
CONCLUSION AND FUTURE WORK
Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call