Abstract
This paper (This work is part of the first author’s Ph.D. thesis [15].) presents a powerful and flexible technique for defining type inference algorithms, on an ML-like language, that involve subtyping and whose soundness can be proved. We define a typing algorithm as a set of inference rules of three distinct forms: typing rules collect subtyping constraints to be satisfied, instantiation rules instantiate type schemes, and saturation rules specify how to check the validity and consistency of collected constraints. Essentially, type inference then proceeds in two intertwined phases: one that extracts constraints and the other that saturates the sets of constraints. Our technique extends easily to the treatment of high-level features such as polymorphism, overloading, variants and pattern-matching, or generalized algebraic data types (GADTs).
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Disjunctions should not be confused with union types.
- 2.
Note that the evaluation order does not interfere with typing, and laziness would not complicate the treatment that is given here.
References
Aiken, A., Wimmers, E.L.: Type inclusion constraints and type inference. In: Functional Programming and Computer Architecture, pp. 31–41. ACM, Copenhagen (1993)
Aiken, A., Wimmers, E.L., Lakshman, T.K.: Soft typing with conditional types. In: Principles of Programming Languages, pp. 163–173. ACM, Portland (1994)
Charguéraud, A., Pottier, F.: Machine-checked verification of the correctness and amortized complexity of an efficient union-find implementation. In: Urban, C., Zhang, X. (eds.) ITP 2015. LNCS, vol. 9236, pp. 137–153. Springer, Cham (2015). https://doi.org/10.1007/978-3-319-22102-1_9
Dolan, S., Mycroft, A.: Polymorphism, subtyping and type inference in MLsub. In: Principles of Programming Languages (2017)
Eifrig, J., Smith, S., Trifonov, V.: Type inference for recursively constrained types and its application to OOP. Electron. Notes Theor. Comput. Sci. 1, 132–153 (1995)
Henglein, F.: Efficient type inference for higher-order binding-time analysis. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 448–472. Springer, Heidelberg (1991). https://doi.org/10.1007/3540543961_22
Martelli, A., Montanari, U.: An efficient unification algorithm. Trans. Program. Lang. Syst. 4(2), 258–282 (1982)
Palmer, Z., Menon, P.H., Rozenshteyn, A., Smith, S.: Types for flexible objects. In: Asian Symposium on Programming Languages and Systems, pp. 99–119 (2014)
Jones, S.P., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unification-based type inference for GADTs. SIGPLAN Not. 41(9), 50–61 (2006)
Pottier, F.: A framework for type inference with subtyping. In: International Conference on Functional Programming, pp. 228–238, September 1998
Pottier, F.: A versatile constraint-based type inference system. Nordic J. Comput. 7(4), 312–347 (2000)
Simonet, V., Pottier, F.: Constraint-based type inference for guarded algebraic data types. Research Report 5462. INRIA, January 2005
Smith, S.F., Wang, T.: Polyvariant flow analysis with constrained types. In: Smolka, G. (ed.) ESOP 2000. LNCS, vol. 1782, pp. 382–396. Springer, Heidelberg (2000). https://doi.org/10.1007/3-540-46425-5_25
Trifonov, V., Smith, S.: Subtyping constrained types. In: Cousot, R., Schmidt, D.A. (eds.) SAS 1996. LNCS, vol. 1145, pp. 349–365. Springer, Heidelberg (1996). https://doi.org/10.1007/3-540-61739-6_52
Vaugon, B., Sous-typage par saturation de contraintes: théorie et implémentation. Ph.D. thesis. Université Paris-Saclay (2016). https://pastel.archives-ouvertes.fr/tel-01356695/document
Wright, A.K., Felleisen, M.: A syntactic approach to type soundness. Inf. Comput. 115, 38–94 (1992)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
A Appendix
A Appendix
We give here the complete set of rules for the language given in Fig. 1.
Meta-functions
The T meta-function associates a type scheme to constants and primitives. For instance:
Typing
Instantiation
Saturation
To prevent our algorithm from entering an infinite loop in the presence of cyclic relations between type variables, before checking the compatibility of a constraint with \(\varPhi \), we check whether this constraint is already present in \(\varPhi \). If not, one of SNewConstraint(\(\leqslant \)) or SNewConstraint(\(\nleqslant \)) is used, and we add the new constraint in \(\varPhi \) and generate a property annotated with a question mark (\(\vdash ^{\!\!\!\!\tiny ?\,}\)) consumed by rules defined further. If so, one of the axioms SAlreadyProved(\(\leqslant \)) or SAlreadyProved(\(\nleqslant \)) is used and no more constraint is generated.
Rights and permissions
Copyright information
© 2019 Springer Nature Switzerland AG
About this paper
Cite this paper
Vaugon, B., Mauny, M. (2019). A Type Inference System Based on Saturation of Subtyping Constraints. In: Van Horn, D., Hughes, J. (eds) Trends in Functional Programming. TFP 2016. Lecture Notes in Computer Science(), vol 10447. Springer, Cham. https://doi.org/10.1007/978-3-030-14805-8_6
Download citation
DOI: https://doi.org/10.1007/978-3-030-14805-8_6
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-14804-1
Online ISBN: 978-3-030-14805-8
eBook Packages: Computer ScienceComputer Science (R0)