Skip to main content

A Type Inference System Based on Saturation of Subtyping Constraints

  • Conference paper
  • First Online:
Trends in Functional Programming (TFP 2016)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 10447))

Included in the following conference series:

  • 280 Accesses

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).

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    Disjunctions should not be confused with union types.

  2. 2.

    Note that the evaluation order does not interfere with typing, and laziness would not complicate the treatment that is given here.

References

  1. Aiken, A., Wimmers, E.L.: Type inclusion constraints and type inference. In: Functional Programming and Computer Architecture, pp. 31–41. ACM, Copenhagen (1993)

    Google Scholar 

  2. Aiken, A., Wimmers, E.L., Lakshman, T.K.: Soft typing with conditional types. In: Principles of Programming Languages, pp. 163–173. ACM, Portland (1994)

    Google Scholar 

  3. 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

    Chapter  Google Scholar 

  4. Dolan, S., Mycroft, A.: Polymorphism, subtyping and type inference in MLsub. In: Principles of Programming Languages (2017)

    Google Scholar 

  5. 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)

    Article  Google Scholar 

  6. 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

    Chapter  Google Scholar 

  7. Martelli, A., Montanari, U.: An efficient unification algorithm. Trans. Program. Lang. Syst. 4(2), 258–282 (1982)

    Article  Google Scholar 

  8. 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)

    Google Scholar 

  9. Jones, S.P., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unification-based type inference for GADTs. SIGPLAN Not. 41(9), 50–61 (2006)

    Article  Google Scholar 

  10. Pottier, F.: A framework for type inference with subtyping. In: International Conference on Functional Programming, pp. 228–238, September 1998

    Google Scholar 

  11. Pottier, F.: A versatile constraint-based type inference system. Nordic J. Comput. 7(4), 312–347 (2000)

    MathSciNet  MATH  Google Scholar 

  12. Simonet, V., Pottier, F.: Constraint-based type inference for guarded algebraic data types. Research Report 5462. INRIA, January 2005

    Google Scholar 

  13. 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

    Chapter  Google Scholar 

  14. 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

    Chapter  Google Scholar 

  15. 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

  16. Wright, A.K., Felleisen, M.: A syntactic approach to type soundness. Inf. Comput. 115, 38–94 (1992)

    Article  MathSciNet  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Benoît Vaugon .

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

figure l

The T meta-function associates a type scheme to constants and primitives. For instance:

Typing

figure m
figure n
figure o
figure p
figure q
figure r
figure s
figure t
figure u
figure v
figure w

Instantiation

figure x

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.

figure y
figure z
figure aa
figure ab
figure ac
figure ad
figure ae
figure af
figure ag
figure ah
figure ai

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

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)

Publish with us

Policies and ethics