Complete and easy type Inference for first-class polymorphism
dc.contributor.advisor
Cheney, James
dc.contributor.advisor
Lindley, Sam
dc.contributor.author
Emrich, Frank
dc.contributor.other
Laboratory for Foundations of Computer Science
en
dc.contributor.sponsor
European Research Council
en
dc.date.accessioned
2024-02-06T15:41:16Z
dc.date.available
2024-02-06T15:41:16Z
dc.date.issued
2024-02-06
dc.description.abstract
The Hindley-Milner (HM) typing discipline is remarkable in that it allows statically typing programs without requiring the programmer to annotate programs with types themselves. This is due to the HM system offering complete type inference, meaning that if a program is well typed, the inference algorithm is able to determine all the necessary typing information. Let bindings implicitly perform generalisation, allowing a let-bound variable to receive the most general possible type, which in turn may be instantiated appropriately at each of the variable’s use sites. As a result, the HM type system has since become the foundation for type inference in programming languages such as Haskell as well as the ML family of languages and has been extended in a multitude of ways.
The original HM system only supports prenex polymorphism, where type variables are universally quantified only at the outermost level. This precludes many useful programs, such as passing a data structure to a function in the form of a fold function, which would need to be polymorphic in the type of the accumulator. However, this would require a nested quantifier in the type of the overall function. As a result, one direction of extending the HM system is to add support for first-class polymorphism, allowing arbitrarily nested quantifiers and instantiating type variables with polymorphic types. In such systems, restrictions are necessary to retain decidability of type inference.
This work presents FreezeML, a novel approach for integrating first-class polymorphism into the HM system, focused on simplicity. It eschews sophisticated yet hard to grasp heuristics in the type systems or extending the language of types, while still requiring only modest amounts of annotations. In particular, FreezeML leverages the mechanisms for generalisation and instantiation that are already at the heart of ML. Generalisation and instantiation are performed by let bindings and variables, respectively, but extended to types beyond prenex polymorphism. The defining feature of FreezeML is the ability to freeze variables, which prevents the usual instantiation of their types, allowing them instead to keep their original, fully polymorphic types.
We demonstrate that FreezeML is as expressive as System F by providing a translation from the latter to the former; the reverse direction is also shown. Further, we prove that FreezeML is indeed a conservative extension of ML: When considering only ML programs, FreezeML accepts exactly the same programs as ML itself. #
We show that type inference for FreezeML can easily be integrated into HM-like type systems by presenting a sound and complete inference algorithm for FreezeML that extends Algorithm W, the original inference algorithm for the HM system.
Since the inception of Algorithm W in the 1970s, type inference for the HM system and its descendants has been modernised by approaches that involve constraint solving, which proved to be more modular and extensible. In such systems, a term is translated to a logical constraint, whose solutions correspond to the types of the original term. A solver for such constraints may then be defined independently. To this end, we demonstrate such a constraint-based inference approach for FreezeML.
We also discuss the effects of integrating the value restriction into FreezeML and provide detailed comparisons with other approaches towards first-class polymorphism in ML alongside a collection of examples found in the literature.
en
dc.identifier.uri
https://hdl.handle.net/1842/41418
dc.identifier.uri
http://dx.doi.org/10.7488/era/4152
dc.language.iso
en
en
dc.publisher
The University of Edinburgh
en
dc.relation.hasversion
Emrich, F., Lindley, S., Stolarek, J., Cheney, J., and Coates, J. (2020). FreezeML: Complete and easy type inference for first-class polymorphism. In Donaldson, A. F. and Torlak, E., editors, Proceedings of the 41st ACM SIGPLAN International Conference on Programming Language Design and Implementation, pages 423–437. ACM
en
dc.relation.hasversion
Emrich, F., Stolarek, J., Cheney, J., and Lindley, S. (2022). Constraint-based type inference for FreezeML. Proceedings of the ACM on Programming Languages, 6(ICFP):570–595
en
dc.subject
programming languages
en
dc.subject
static type system
en
dc.subject
reliability
en
dc.subject
polymorphism
en
dc.subject
supporting types
en
dc.subject
Hindley-Milner
en
dc.subject
ML language
en
dc.subject
first-class polymorphism
en
dc.subject
FreezeML
en
dc.title
Complete and easy type Inference for first-class polymorphism
en
dc.type
Thesis or Dissertation
en
dc.type.qualificationlevel
Doctoral
en
dc.type.qualificationname
PhD Doctor of Philosophy
en
Files
Original bundle
1 - 1 of 1
- Name:
- Emrich2024.pdf
- Size:
- 1.2 MB
- Format:
- Adobe Portable Document Format
- Description:
This item appears in the following Collection(s)

