Abstract

We extend classic union and intersection type systems with a type-case construction and show that the combination of the union elimination rule of the former and the typing rules for type-cases of our extension encompasses occurrence typing . To apply this system in practice, we define a canonical form for the expressions of our extension, called MSC-form. We show that an expression of the extension is typable if and only if its MSC-form is, and reduce the problem of typing the latter to the one of reconstructing annotations for that term. We provide a sound algorithm that performs this reconstruction and a proof-of-concept implementation.

Highlights

  • TypeScript [Microsoft] and Flow [Facebook] are extensions of JavaScript that allow the programmer to specify in the code type annotations used to statically type-check the program

  • To cope with occurrence typing we extend, in a nutshell, the system of [Barbanera et al 1995] with three simple ingredients: (1) we add to its expressions the type-case expression (e∈t) ? e : e; (2) we add to its types the negation connective and the empty type; (3) we add to its deduction rules the typing rules for type-cases we showed before

  • This work provides four main technical contributions. (i) We show how to extend the system of Barbanera et al [1995] with negation types and type-cases and prove its soundness (ğ2); (ii) we define MSC-forms and prove that the problem of typing a term of the previous system is equivalent to the one of typing its MSC-form (ğ3); (iii) we prove that the latter problem is equivalent to adding type annotations in a MSC-form so that it becomes a well-typed term and that checking well-typedness of an annotated MSC-form is decidable (ğ4); (iv) we define a sound reconstruction algorithm for the annotations of a MSC-form (ğ5) and provide an implementation (ğ6)

Read more

Summary

INTRODUCTION

TypeScript [Microsoft] and Flow [Facebook] are extensions of JavaScript that allow the programmer to specify in the code type annotations used to statically type-check the program. By the definition of MSC-forms, it circumscribes the use of union elimination to a very specific setting, advancing in the quest for the characterization of inversion of union rules It shows that well-typing in such systems is equivalent to the problem of reconstructing annotations for MSC-forms, providing a formal yard-stick to compare different approaches. We exploited this new setting to define a sound reconstruction algorithm that we rendered in a proof-of-concept implementation. Standard pattern matching cannot check function types, so the restriction is not a problem for this Typecases of this form have the same expressiveness as the type-testing primitives of dynamic languages like JavaScript and Racket. Since every test type τ is a type, in what follows we may sometimes use the metavariable t to denote test types when this is clear from the context

Reduction Semantics
Type System
Type Soundness
INTERMEDIATE SYSTEM
Expressions with Bindings
Intermediate Typing Rules
Maximal Sharing Canonical Forms
ALGORITHMIC SYSTEM
Algorithmic Expressions and Typing Rules
ALGORITHM FOR RECONSTRUCTING ANNOTATIONS
IMPLEMENTATION
RELATED WORK
CONCLUSION
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