-
Polymorphic Records for Dynamic Languages
Authors:
Giuseppe Castagna,
Loïc Peyrot
Abstract:
We define and study "row polymorphism" for a type system with set-theoretic types, specifically union, intersection, and negation types. We consider record types that embed row variables and define a subty** relation by interpreting types into sets of record values and by defining subty** as the containment of interpretations. We define a functional calculus equipped with operations for field…
▽ More
We define and study "row polymorphism" for a type system with set-theoretic types, specifically union, intersection, and negation types. We consider record types that embed row variables and define a subty** relation by interpreting types into sets of record values and by defining subty** as the containment of interpretations. We define a functional calculus equipped with operations for field extension, selection, and deletion, its operational semantics, and a type system that we prove to be sound. We provide algorithms for deciding the ty** and subty** relations.
This research is motivated by the current trend of defining static type system for dynamic languages and, in our case, by an ongoing effort of endowing the Elixir programming language with a gradual type system.
△ Less
Submitted 30 March, 2024;
originally announced April 2024.
-
Polymorphic Type Inference for Dynamic Languages
Authors:
Giuseppe Castagna,
Mickaël Laurent,
Kim Nguyen
Abstract:
We present a type system that combines, in a controlled way, first-order polymorphism with intersectiontypes, union types, and subty**, and prove its safety. We then define a type reconstruction algorithm that issound and terminating. This yields a system in which unannotated functions are given polymorphic types(thanks to Hindley-Milner) that can express the overloaded behavior of the functions…
▽ More
We present a type system that combines, in a controlled way, first-order polymorphism with intersectiontypes, union types, and subty**, and prove its safety. We then define a type reconstruction algorithm that issound and terminating. This yields a system in which unannotated functions are given polymorphic types(thanks to Hindley-Milner) that can express the overloaded behavior of the functions they type (thanks tothe intersection introduction rule) and that are deduced by applying advanced techniques of type narrowing(thanks to the union elimination rule). This makes the system a prime candidate to type dynamic languages.
△ Less
Submitted 17 November, 2023;
originally announced November 2023.
-
The Design Principles of the Elixir Type System
Authors:
Giuseppe Castagna,
Guillaume Duboc,
José Valim
Abstract:
Elixir is a dynamically-typed functional language running on the Erlang Virtual Machine, designed for building scalable and maintainable applications. Its characteristics have earned it a surging adoption by hundreds of industrial actors and tens of thousands of developers. Static ty** seems nowadays to be the most important request coming from the Elixir community. We present a gradual type sys…
▽ More
Elixir is a dynamically-typed functional language running on the Erlang Virtual Machine, designed for building scalable and maintainable applications. Its characteristics have earned it a surging adoption by hundreds of industrial actors and tens of thousands of developers. Static ty** seems nowadays to be the most important request coming from the Elixir community. We present a gradual type system we plan to include in the Elixir compiler, outline its characteristics and design principles, and show by some short examples how to use it in practice.
Develo** a static type system suitable for Erlang's family of languages has been an open research problem for almost two decades. Our system transposes to this family of languages a polymorphic type system with set-theoretic types and semantic subty**. To do that, we had to improve and extend both semantic subty** and the ty** techniques thereof, to account for several characteristics of these languages -- and of Elixir in particular -- such as the arity of functions, the use of guards, a uniform treatment of records and dictionaries, the need for a new sound gradual ty** discipline that does not rely on the insertion at compile time of specific run-time type-tests but, rather, takes into account both the type tests performed by the virtual machine and those explicitly added by the programmer.
The system presented here is "gradually" being implemented and integrated in Elixir, but a prototype implementation is already available.
The aim of this work is to serve as a longstanding reference that will be used to introduce types to Elixir programmers, as well as to hint at some future directions and possible evolutions of the Elixir language.
△ Less
Submitted 29 December, 2023; v1 submitted 10 June, 2023;
originally announced June 2023.
-
Programming with union, intersection, and negation types
Authors:
Giuseppe Castagna
Abstract:
In this essay, I present the advantages and, I dare say, the beauty of programming in a language with set-theoretic types, that is, types that include union, intersection, and negation type connectives. I show by several examples how set-theoretic types are necessary to type some common programming patterns, but also how they play a key role in ty** several language constructs-from branching and…
▽ More
In this essay, I present the advantages and, I dare say, the beauty of programming in a language with set-theoretic types, that is, types that include union, intersection, and negation type connectives. I show by several examples how set-theoretic types are necessary to type some common programming patterns, but also how they play a key role in ty** several language constructs-from branching and pattern matching to function overloading and type-cases-very precisely. I start by presenting the theory of types known as semantic subty** and extend it to include polymorphic types. Next, I discuss the design of languages that use these types. I start by defining a theoretical framework that covers all the examples given in the first part of the presentation. Since the system of the framework cannot be effectively implemented, I then describe three effective restrictions of this system: (i) a polymorphic language with explicitly-typed functions, (ii) an implicitly-typed polymorphic language à la Hindley-Milner, and (iii) a monomorphic language that, by implementing classic union-elimination, precisely reconstructs intersection types for functions and implements a very general form of occurrence ty**. I conclude the presentation with a short overview of other aspects of these languages, such as pattern matching, gradual ty**, and denotational semantics.
△ Less
Submitted 27 March, 2024; v1 submitted 5 November, 2021;
originally announced November 2021.
-
Revisiting Occurrence Ty**
Authors:
Giuseppe Castagna,
Victor Lanvin,
Mickaël Laurent,
Kim Nguyen
Abstract:
We revisit occurrence ty**, a technique to refine the type of variables occurring in type-cases and, thus, capturesome programming patterns used in untyped languages. Although occurrence ty** was tied from its inceptionto set-theoretic types-union types, in particular-it never fully exploited the capabilities of these types. Here weshow how, by using set-theoretic types, it is possible to deve…
▽ More
We revisit occurrence ty**, a technique to refine the type of variables occurring in type-cases and, thus, capturesome programming patterns used in untyped languages. Although occurrence ty** was tied from its inceptionto set-theoretic types-union types, in particular-it never fully exploited the capabilities of these types. Here weshow how, by using set-theoretic types, it is possible to develop a general ty** framework that encompasses andgeneralizes several aspects of current occurrence ty** proposals and that can be applied to tackle other problemssuch as the reconstruction of intersection types for unannotated or partially annotated functions and the optimizationof the compilation of gradually typed languages.
△ Less
Submitted 12 February, 2022; v1 submitted 12 July, 2019;
originally announced July 2019.
-
Semantic subty** for non-strict languages
Authors:
Tommaso Petrucciani,
Giuseppe Castagna,
Davide Ancona,
Elena Zucca
Abstract:
Semantic subty** is an approach to define subty** relations for type systems featuring union and intersection type connectives. It has been studied only for strict languages, and it is unsound for non-strict semantics. In this work, we study how to adapt this approach to non-strict languages: in particular, we define a type system using semantic subty** for a functional language with a call-…
▽ More
Semantic subty** is an approach to define subty** relations for type systems featuring union and intersection type connectives. It has been studied only for strict languages, and it is unsound for non-strict semantics. In this work, we study how to adapt this approach to non-strict languages: in particular, we define a type system using semantic subty** for a functional language with a call-by-need semantics. We do so by introducing an explicit representation for divergence in the types, so that the type system distinguishes expressions that are results from those which are computations that might diverge.
△ Less
Submitted 16 October, 2018; v1 submitted 12 October, 2018;
originally announced October 2018.
-
Covariance and Controvariance: a fresh look at an old issue (a primer in advanced type systems for learning functional programmers)
Authors:
Giuseppe Castagna
Abstract:
Twenty years ago, in an article titled "Covariance and contravariance: conflict without a cause", I argued that covariant and contravariant specialization of method parameters in object-oriented programming had different purposes and deduced that, not only they could, but actually they should both coexist in the same language.
In this work I reexamine the result of that article in the light of r…
▽ More
Twenty years ago, in an article titled "Covariance and contravariance: conflict without a cause", I argued that covariant and contravariant specialization of method parameters in object-oriented programming had different purposes and deduced that, not only they could, but actually they should both coexist in the same language.
In this work I reexamine the result of that article in the light of recent advances in (sub-)ty** theory and programming languages, taking a fresh look at this old issue.
Actually, the revam** of this problem is just an excuse for writing an essay that aims at explaining sophisticated type-theoretic concepts, in simple terms and by examples, to undergraduate computer science students and/or willing functional programmers.
Finally, I took advantage of this opportunity to describe some undocumented advanced techniques of type-systems implementation that are known only to few insiders that dug in the code of some compilers: therefore, even expert language designers and implementers may find this work worth of reading.
△ Less
Submitted 21 February, 2022; v1 submitted 5 September, 2018;
originally announced September 2018.
-
Set-Theoretic Types for Polymorphic Variants
Authors:
Giuseppe Castagna,
Tommaso Petrucciani,
Kim Nguyen
Abstract:
Polymorphic variants are a useful feature of the OCaml language whose current definition and implementation rely on kinding constraints to simulate a subty** relation via unification. This yields an awkward formalization and results in a type system whose behaviour is in some cases unintuitive and/or unduly restrictive. In this work, we present an alternative formalization of poly-morphic varian…
▽ More
Polymorphic variants are a useful feature of the OCaml language whose current definition and implementation rely on kinding constraints to simulate a subty** relation via unification. This yields an awkward formalization and results in a type system whose behaviour is in some cases unintuitive and/or unduly restrictive. In this work, we present an alternative formalization of poly-morphic variants, based on set-theoretic types and subty**, that yields a cleaner and more streamlined system. Our formalization is more expressive than the current one (it types more programs while preserving type safety), it can internalize some meta-theoretic properties, and it removes some pathological cases of the current implementation resulting in a more intuitive and, thus, predictable type system. More generally, this work shows how to add full-fledged union types to functional languages of the ML family that usually rely on the Hindley-Milner type system. As an aside, our system also improves the theory of semantic subty**, notably by proving completeness for the type reconstruction algorithm.
△ Less
Submitted 5 July, 2016; v1 submitted 3 June, 2016;
originally announced June 2016.
-
Static and dynamic semantics of NoSQL languages
Authors:
Véronique Benzaken,
Giuseppe Castagna,
Kim Nguy\~ên,
Jérôme Siméon
Abstract:
We present a calculus for processing semistructured data that spans differences of application area among several novel query languages, broadly categorized as "NoSQL". This calculus lets users define their own operators, capturing a wider range of data processing capabilities, whilst providing a ty** precision so far typical only of primitive hard-coded operators. The type inference algorithm i…
▽ More
We present a calculus for processing semistructured data that spans differences of application area among several novel query languages, broadly categorized as "NoSQL". This calculus lets users define their own operators, capturing a wider range of data processing capabilities, whilst providing a ty** precision so far typical only of primitive hard-coded operators. The type inference algorithm is based on semantic type checking, resulting in type information that is both precise, and flexible enough to handle structured and semistructured data. We illustrate the use of this calculus by encoding a large fragment of Jaql, including operations and iterators over JSON, embedded SQL expressions, and co-grou**, and show how the encoding directly yields a ty** discipline for Jaql as it is, namely without the addition of any type definition or type annotation in the code.
△ Less
Submitted 7 March, 2013;
originally announced March 2013.
-
On Global Types and Multi-Party Session
Authors:
Giuseppe Castagna,
Mariangiola Dezani-Ciancaglini,
Luca Padovani
Abstract:
Global types are formal specifications that describe communication protocols in terms of their global interactions. We present a new, streamlined language of global types equipped with a trace-based semantics and whose features and restrictions are semantically justified. The multi-party sessions obtained projecting our global types enjoy a liveness property in addition to the traditional progres…
▽ More
Global types are formal specifications that describe communication protocols in terms of their global interactions. We present a new, streamlined language of global types equipped with a trace-based semantics and whose features and restrictions are semantically justified. The multi-party sessions obtained projecting our global types enjoy a liveness property in addition to the traditional progress and are shown to be sound and complete with respect to the set of traces of the originating global type. Our notion of completeness is less demanding than the classical ones, allowing a multi-party session to leave out redundant traces from an underspecified global type. In addition to the technical content, we discuss some limitations of our language of global types and provide an extensive comparison with related specification languages adopted in different communities.
△ Less
Submitted 13 March, 2012; v1 submitted 4 March, 2012;
originally announced March 2012.
-
Optimizing XML querying using type-based document projection
Authors:
Véronique Benzaken,
Giuseppe Castagna,
Dario Colazzo,
Kim Nguyen
Abstract:
XML data projection (or pruning) is a natural optimization for main memory query engines: given a query Q over a document D, the subtrees of D that are not necessary to evaluate Q are pruned, thus producing a smaller document D'; the query Q is then executed on D', hence avoiding to allocate and process nodes that will never be reached by Q. In this article, we propose a new approach, based on typ…
▽ More
XML data projection (or pruning) is a natural optimization for main memory query engines: given a query Q over a document D, the subtrees of D that are not necessary to evaluate Q are pruned, thus producing a smaller document D'; the query Q is then executed on D', hence avoiding to allocate and process nodes that will never be reached by Q. In this article, we propose a new approach, based on types, that greatly improves current solutions. Besides providing comparable or greater precision and far lesser pruning overhead, our solution ---unlike current approaches--- takes into account backward axes, predicates, and can be applied to multiple queries rather than just to single ones. A side contribution is a new type system for XPath able to handle backward axes. The soundness of our approach is formally proved. Furthermore, we prove that the approach is also complete (i.e., yields the best possible type-driven pruning) for a relevant class of queries and Schemas. We further validate our approach using the XMark and XPathMark benchmarks and show that pruning not only improves the main memory query engine's performances (as expected) but also those of state of the art native XML databases.
△ Less
Submitted 11 April, 2011;
originally announced April 2011.