Skip to main content

Type Inference for Rank 2 Gradual Intersection Types

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

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

Included in the following conference series:

Abstract

In this paper, we extend a rank 2 intersection type system with gradual types. We then show that the problem of finding a principal typing for a lambda term, in a rank 2 gradual intersection type system is decidable. We present a type inference algorithm which builds the principal typing of a term through the generation of type constraints which are solved by a new extended unification algorithm constructing the most general unifier for rank 2 gradual intersection types.

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

References

  1. Barendregt, H., Coppo, M., Dezani-Ciancaglini, M.: A filter lambda model and the completeness of type assignment. J. Symbolic Logic 48(4), 931–940 (1983)

    MathSciNet  MATH  Google Scholar 

  2. Castagna, G., Lanvin, V.: Gradual typing with union and intersection types. Proc. ACM Program. Lang. 1(ICFP), 41:1–41:28 (2017)

    Google Scholar 

  3. Castagna, G., Lanvin, V., Petrucciani, T., Siek, J.G.: Gradual typing: a new perspective. Proc. ACM Program. Lang. 3(POPL), 16:1–16:32 (2019)

    Google Scholar 

  4. Chaudhuri, A.: Flow: abstract interpretation of Javascript for type checking and beyond. In: Proceedings of the 2016 ACM Workshop on Programming Languages and Analysis for Security, PLAS 2016. ACM (2016)

    Google Scholar 

  5. Cimini, M., Siek, J.G.: The gradualizer: a methodology and algorithm for generating gradual type systems. In: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, pp. 443–455 (2016)

    Google Scholar 

  6. Cimini, M., Siek, J.G.: Automatically generating the dynamic semantics of gradually typed languages. In: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, pp. 789–803 (2017)

    Google Scholar 

  7. Coppo, M., Dezani-Ciancaglini, M.: An extension of the basic functionality theory for the \(\lambda \)-calculus. Notre Dame J. Form. Log. 21(4), 685–693 (1980)

    MathSciNet  MATH  Google Scholar 

  8. Coppo, M., Dezani-Ciancaglini, M., Venneri, B.: Functional characters of solvable terms. Math. Logic Quart. 27(2–6), 45–58 (1981)

    MathSciNet  MATH  Google Scholar 

  9. Damas, L., Milner, R.: Principal type-schemes for functional programs. In: Proceedings of the 9th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1982, pp. 207–212 (1982)

    Google Scholar 

  10. Frisch, A., Castagna, G., Benzaken, V.: Semantic subtyping: dealing set-theoretically with function, union, intersection, and negation types. J. ACM 55(4), 19:1–19:64 (2008)

    MathSciNet  MATH  Google Scholar 

  11. Garcia, R., Cimini, M.: Principal type schemes for gradual programs. In: Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, pp. 303–315 (2015)

    Google Scholar 

  12. Garcia, R., Clark, A.M., Tanter, É.: Abstracting gradual typing. In: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, pp. 429–442 (2016)

    Google Scholar 

  13. Roger Hindley, J.: Basic Simple Type Theory. Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, Cambridge (1997)

    MATH  Google Scholar 

  14. Hindley, R.: The principal type-scheme of an object in combinatory logic. Trans. Am. Math. Soc. 146, 29–60 (1969)

    MathSciNet  MATH  Google Scholar 

  15. Jim, T.: Rank 2 type systems and recursive definitions. Technical report (1995)

    Google Scholar 

  16. Jim, T.: What are principal typings and what are they good for? In: Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1996, pp. 42–53 (1996)

    Google Scholar 

  17. Kfoury, A.J., Wells, J.B.: Principality and decidable type inference for finite-rank intersection types. In: Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 1999, pp. 161–174 (1999)

    Google Scholar 

  18. Kfoury, A.J., Wells, J.B.: Principality and type inference for intersection types using expansion variables. Theoret. Comput. Sci. 311(1), 1–70 (2004)

    MathSciNet  MATH  Google Scholar 

  19. Leivant, D.: Polymorphic type inference. In: Proceedings of the 10th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, POPL 1983, pp. 88–98 (1983)

    Google Scholar 

  20. Milner, R.: A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17(3), 348–375 (1978)

    MathSciNet  MATH  Google Scholar 

  21. Reynolds, J.C.: The coherence of languages with intersection types. In: Ito, T., Meyer, A.R. (eds.) TACS 1991. LNCS, vol. 526, pp. 675–700. Springer, Heidelberg (1991). https://doi.org/10.1007/3-540-54415-1_70

    Chapter  Google Scholar 

  22. Reynolds, J.C.: Design of the Programming Language Forsythe, pp. 173–233. Birkhäuser Boston, Boston (1997)

    Google Scholar 

  23. Robinson, J.A.: A machine-oriented logic based on the resolution principle. J. ACM 12(1), 23–41 (1965)

    MathSciNet  MATH  Google Scholar 

  24. Siek, J.G., Vachharajani, M.: Gradual typing with unification-based inference. In: Proceedings of the 2008 Symposium on Dynamic Languages, DLS 2008, pp. 7:1–7:12 (2008)

    Google Scholar 

  25. van Bakel, S.: Intersection type assignment systems. Theoret. Comput. Sci. 151(2), 385–435 (1995)

    MathSciNet  MATH  Google Scholar 

  26. Vekris, P., Cosman, B., Jhala, R.: Refinement types for typescript. SIGPLAN Not. 51(6), 310–325 (2016)

    Google Scholar 

  27. Wand, M.: A simple algorithm and proof for type inference. Fundamenta Informaticae 10(2), 115–121 (1987)

    MathSciNet  MATH  Google Scholar 

  28. Wells, J.B.: The essence of principal typings. In: Widmayer, P., Eidenbenz, S., Triguero, F., Morales, R., Conejo, R., Hennessy, M. (eds.) ICALP 2002. LNCS, vol. 2380, pp. 913–925. Springer, Heidelberg (2002). https://doi.org/10.1007/3-540-45465-9_78

    Chapter  Google Scholar 

  29. Ângelo, P., Florido, M.: Gradual intersection types. In: Ninth Workshop on Intersection Types and Related Systems, ITRS 2018, Oxford, UK, 8 July 2018 (2018)

    Google Scholar 

Download references

Acknowledgments

This work is partially funded by FCT within project Elven POCI-01-0145-FEDER-016844, Project 9471 - Reforçar a Investigação, o Desenvolvimento Tecnológico e a Inovação (Project 9471-RIDTI) and by Fundo Comunitário Europeu FEDER.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Pedro Ângelo .

Editor information

Editors and Affiliations

A   Proofs

A   Proofs

Lemma 9

(Weakening). If \(\varGamma \ \vdash _{\cap G}e : T\) then \(\varGamma + \varGamma ' \vdash _{\cap G}e : T\) for any typing context \(\varGamma '\).

Proof

We proceed by induction on the derivation tree of \(\varGamma \vdash _{\cap G}e : T\).

Base cases:

  • Rule T-Var. If \(\varGamma \vdash _{\cap G}x : T_i\) then \(x : T_1 \cap \ldots \cap T_n \in \varGamma \). If \(x : T_1' \cap \ldots \cap T_m' \in \varGamma '\), then \(x : T_1 \cap \ldots \cap T_n \cap T_1' \cap \ldots \cap T_m' \in \varGamma + \varGamma '\). Therefore, \(\varGamma + \varGamma ' \vdash _{\cap G}x : T_i\).

  • Rule T-Const. If \(\varGamma \vdash _{\cap G}c : T\) and c is a constant of type T, then \(\varGamma + \varGamma ' \vdash _{\cap G}c : T\).

Induction step:

  • Rule T-Abs. To avoid capture we assume that \(\alpha -reduction\) is made whenever needed to rename formal parameters. If \(\varGamma \vdash _{\cap G}\lambda x\ .\ e : T_1 \rightarrow T_2\) then \(\varGamma , x : T_1 \vdash _{\cap G}e : T_2\). By induction hypothesis, \(\varGamma , x : T_1 + \varGamma ' \vdash _{\cap G}e : T_2\). By rule T-Abs, \(\varGamma + \varGamma ' \vdash _{\cap G}\lambda x \ .\ e : T_1 \rightarrow T_2\).

  • Rule T-Abs. To avoid capture we assume that \(\alpha -reduction\) is made whenever needed to rename formal parameters. If \(\varGamma \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : T_1 \cap \ldots \cap T_m \rightarrow T\) then \(\varGamma , x : T_1 \cap \ldots \cap T_m \vdash _{\cap G}e : T\). By induction hypothesis, \(\varGamma , x : T_1 \cap \ldots \cap T_m + \varGamma ' \vdash _{\cap G}e : T\). By rule T-Abs:, \(\varGamma + \varGamma ' \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : T_1 \cap \ldots \cap T_m \rightarrow T\).

  • Rule T-App. If \(\varGamma \vdash _{\cap G}e_1\ e_2 : T\) then \(\varGamma \vdash _{\cap G}e_1 : PM\), \(PM \rhd T_1 \cap \ldots \cap T_n \rightarrow T\), \(\varGamma \vdash _{\cap G}e_2 : T_1' \cap \ldots \cap T_n'\) and \(T_1' \lesssim T_1 \ldots T_n' \lesssim T_n\). By induction hypothesis, \(\varGamma + \varGamma ' \vdash _{\cap G}e_1 : PM\) and \(\varGamma + \varGamma ' \vdash _{\cap G}e_2 : T_1' \cap \ldots \cap T_n'\). By rule T-App, \(\varGamma + \varGamma ' \vdash _{\cap G}e_1\ e_2 : T\).

  • Rule T-Gen. If \(\varGamma \vdash _{\cap G}e : T_1 \cap \ldots \cap T_n\) then \(\varGamma \vdash _{\cap G}e : T_1\) and \(\ldots \) and \(\varGamma \vdash _{\cap G}e : T_n\). By induction hypothesis, \(\varGamma + \varGamma ' \vdash _{\cap G}e : T_1\) and \(\ldots \) and \(\varGamma + \varGamma ' \vdash _{\cap G}e : T_n\). By rule T-Gen, \(\varGamma + \varGamma ' \vdash _{\cap G}e : T_1 \cap \ldots \cap T_n\).

  • Rule T-Inst. If \(\varGamma \vdash _{\cap G}e : T_i\) then \(\varGamma \vdash _{\cap G}e : T_1 \cap \ldots \cap T_n\). By induction hypothesis, \(\varGamma + \varGamma ' \vdash _{\cap G}e : T_1 \cap \ldots \cap T_n\). By rule T-Inst, \(\varGamma + \varGamma ' \vdash _{\cap G}e : T_i\)

Lemma 1 (Constraint Soundness). If \(A\ |\ \varGamma \vdash _{\cap G}e : T\ |\ C\) and \(S\,\models \,C\) then \(S(\varGamma ) \vdash _{\cap G}S(e) : S(T)\) .

Proof

We proceed by induction on the length of the derivation tree of \(A\ |\ \varGamma \vdash _{\cap G}e : T\ |\ C\).

Base cases:

  • Rule C-Var1. If \(A\ |\ \{x : T_i\} \vdash _{\cap G}x : T_i\ |\ \{\}\) and \(S\,\models \,\{\}\) then \(\{x : S(T_i)\} \vdash _{\cap G}x : S(T_i)\). Since \(S(\{x : T_i\}) = \{x : S(T_i)\}\) and \(S(x) = x\), then \(S(\{x : T_i\}) \vdash _{\cap G}S(x) : S(T_i)\).

  • Rule C-Var2. If \(A\ |\ \{x : X\} \vdash _{\cap G}x : X\ |\ \{\}\) and \(S\,\models \,\{\}\) then \(\{x : S(X)\} \vdash _{\cap G}x : S(X)\). Since \(S(\{x : X\}) = \{x : S(X)\}\) and \(S(x) = x\), then \(S(\{x : X\}) \vdash _{\cap G}S(x) : S(X)\).

  • Rule C-Const. If \(A\ |\ \{\} \vdash _{\cap G}c : T\ |\ \{\}\) and \(S\,\models \,\emptyset \) then c is a constant of type T. Therefore, \(S(\{\}) \vdash _{\cap G}S(c) : S(T)\).

Induction step:

  • Rule C-Abs1. If \(A\ |\ \varGamma _x \vdash _{\cap G}\lambda x\ .\ e : \varGamma (x) \rightarrow T\ |\ C\) and \(S\,\models \,C\) then \(A\ |\ \varGamma \vdash _{\cap G}e : T\ |\ C\). By the induction hypothesis, \(S(\varGamma ) \vdash _{\cap G}S(e) : S(T)\). Then, by rule T-Abs, \(S(\varGamma )_x \vdash _{\cap G}\lambda x\ .\ S(e) : S(\varGamma (x)) \rightarrow S(T)\). As \(S(\varGamma _x) = S(\varGamma )_x\), \(S(\lambda x\ .\ e) = \lambda x\ .\ S(e)\) and \(S(\varGamma (x) \rightarrow T) = S(\varGamma (x)) \rightarrow S(T)\) then \(S(\varGamma _x) \vdash _{\cap G}S(\lambda x\ .\ e) : S(\varGamma (x) \rightarrow T)\).

  • Rule C-Abs2. If \(A\ |\ \varGamma \vdash _{\cap G}\lambda x\ .\ e : X \rightarrow T\ |\ C\) and \(S\,\models \,C\) then \(A\ |\ \varGamma \vdash _{\cap G}e : T\ |\ C\). By the induction hypothesis, \(S(\varGamma ) \vdash _{\cap G}S(e) : S(T)\). As x : S(X) is not used to type e and thus \(x \not \in \varGamma \) then we also have \(S(\varGamma ) \cup \{x : S(X)\} \vdash _{\cap G}S(e) : S(T)\). Then by the T-Abs, \(S(\varGamma ) \vdash _{\cap G}S(\lambda x\ .\ e) : S(X \rightarrow T)\).

  • Rule C-Abs:1. If \(A\ |\ \varGamma _x \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : \varGamma (x) \rightarrow T\ |\ C\) and \(S\,\models \,C\) then \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma \vdash _{\cap G}e : T\ |\ C\). By the induction hypothesis, \(S(\varGamma ) \vdash _{\cap G}S(e) : S(T)\). Therefore, \(S(\varGamma )_x \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ S(e) : S(\varGamma (x)) \rightarrow S(T)\). As \(S(\varGamma _x) = S(\varGamma )_x\), \(S(\varGamma (x) \rightarrow T) = S(\varGamma (x)) \rightarrow S(T)\) and \(\{x : T_1 \cap \ldots \cap T_m\} \in \varGamma \) then \(S(\varGamma _x) \vdash _{\cap G}\lambda x : S(T_1 \cap \ldots \cap T_m) \cap T_{m+1} \cap \ldots \cap T_n\ .\ S(e) : S(\varGamma (x) \rightarrow T)\). As \(T_{m+1} \cap \ldots \cap T_n\) does not occur in e, then those those types are not affected by substitutions. Therefore, \(S(\varGamma _x) \vdash _{\cap G}S(\lambda x : T_1 \cap \ldots \cap T_n\ .\ e) : S(\varGamma (x) \rightarrow T)\).

  • Rule C-Abs:2. If \(A\ |\ \varGamma \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : T_1 \rightarrow T \cap \ldots \cap T_n \rightarrow T\ |\ C\) and \(S\,\models \,C\) then \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma \vdash _{\cap G}e : T\ |\ C\). By the induction hypothesis, \(S(\varGamma ) \vdash _{\cap G}S(e) : S(T)\). As \(x \not \in dom(\varGamma )\) then x doesn’t occur in e. Therefore, we also have \(S(\varGamma ) \cup \{x : S(T_1)\} \vdash _{\cap G}S(e) : S(T)\) and \(\ldots \) and \(S(\varGamma ) \cup \{x : S(T_n)\} \vdash _{\cap G}S(e) : S(T)\). Then, by rule T-Abs:, \(S(\varGamma ) \vdash _{\cap G}S(\lambda x : T_1 \cap \ldots \cap T_n\ .\ e) : S(T_1 \rightarrow T)\) and \(\ldots \) and \(S(\varGamma ) \vdash _{\cap G}S(\lambda x : T_1 \cap \ldots \cap T_n\ .\ e) : S(T_n \rightarrow T)\). By rule T-Gen, we have \(S(\varGamma ) \vdash _{\cap G}S(\lambda x : T_1 \cap \ldots \cap T_n\ .\ e) : S(T_1 \rightarrow T \cap \ldots \cap T_n \rightarrow T)\).

  • Rule C-App. If \(A\ |\ \varGamma _1 + \varGamma _2 \vdash _{\cap G}e_1\ e_2 : T_3\ |\ C_1 \cup C_2 \cup C_3 \cup C_4\) and \(S\,\models \,C_1 \cup C_2 \cup C_3 \cup C_4\) then \(A\ |\ \varGamma _1 \vdash _{\cap G}e_1 : T_1\ |\ C_1\) and \(A\ |\ \varGamma _2 \vdash _{\cap G}e_2 : T_2\ |\ C_2\) and \(cod(T_1) \doteq T_3\ |\ C_3\) and \(T_2\ \dot{\lesssim }\ dom(T_1)\ |\ C_4\). There are three possibilities:

    • \(T_1 = X\). Then, \(T_3 = X_2\). By the induction hypothesis, \(S(\varGamma _1) \vdash _{\cap G}S(e_1) : S(X)\) and \(S(\varGamma _2) \vdash _{\cap G}S(e_2) : S(T_2)\). As \(S\,\models \,\{X \doteq X_1 \rightarrow X_2, X \doteq X_3 \rightarrow X_4, T_2\ \dot{\lesssim }\ X_1\}\), then \(S(\varGamma _1) \vdash _{\cap G}S(e_1) : S(X_1 \rightarrow X_2)\) and \(S(T_2) \lesssim S(X_1)\). Therefore, \(S(\varGamma _1) \vdash _{\cap G}S(e_1) : S(X_1) \rightarrow S(X_2)\). Therefore, by Lemma 9, \(S(\varGamma _1 + \varGamma _2) \vdash _{\cap G}S(e_1\ e_2) : S(X_2)\).

    • \(T_1 = T_{11} \rightarrow T_{12}\). Then, \(T_3 = T_{12}\). By the induction hypothesis, \(S(\varGamma _1) \vdash _{\cap G}S(e_1) : S(T_{11} \rightarrow T_{12})\) and \(S(\varGamma _2) \vdash _{\cap G}S(e_2) : S(T_2)\). Therefore, \(S(\varGamma _1) \vdash _{\cap G}S(e_1) : S(T_{11}) \rightarrow S(T_{12})\). As \(S\,\models \,T_2\ \dot{\lesssim }\ T_{11}\), then \(S(T_2) \lesssim S(T_{11})\). Therefore, by Lemma 9, \(S(\varGamma _1 + \varGamma _2) \vdash _{\cap G}S(e_1\ e_2) : S(T_{12})\).

    • \(T_1 = { Dyn }\). Then \(T_3 = { Dyn }\). By the induction hypothesis, \(S(\varGamma _1) \vdash _{\cap G}S(e_1) : S({ Dyn })\) and \(S(\varGamma _2) \vdash _{\cap G}S(e_2) : S(T_2)\). Therefore, \(S(\varGamma _1) \vdash _{\cap G}S(e_1) : { Dyn }\) and \({ Dyn }\rhd { Dyn }\rightarrow { Dyn }\). As \(S(T_2) \lesssim { Dyn }\) then, by Lemma 9, \(S(\varGamma _1 + \varGamma _2) \vdash _{\cap G}S(e_1\ e_2) : S({ Dyn })\).

  • Rule C-App\(\cap \). If \(A\ |\ \varGamma + \varGamma _1 + \ldots + \varGamma _n \vdash _{\cap G}e_1\ e_2 : T\ |\ C \cup C_1 \cup \{T_1'\ \dot{\lesssim }\ T_1\} \cup \ldots \cup C_n \cup \{T_n'\ \dot{\lesssim }\ T_n\}\) and \(S\,\models \,C \cup C_1 \cup \{T_1'\ \dot{\lesssim }\ T_1\} \cup \ldots \cup C_n \cup \{T_n'\ \dot{\lesssim }\ T_n\}\) then \(A\ |\ \varGamma \vdash _{\cap G}e_1 : T_1 \cap \ldots \cap T_n \rightarrow T\ |\ C\) and \(A\ |\ \varGamma _1 \vdash _{\cap G}e_2 : T_1'\ |\ C_1\) and \(\ldots \) and \(A\ |\ \varGamma _n \vdash _{\cap G}e_2 : T_n'\ |\ C_n\) and \(S(T_1') \lesssim S(T_1)\) and \(\ldots \) and \(S(T_n') \lesssim S(T_n)\). By the induction hypothesis, \(S(\varGamma ) \vdash _{\cap G}S(e_1) : S(T_1 \cap \ldots \cap T_n \rightarrow T)\) and \(S(\varGamma _1) \vdash _{\cap G}S(e_2) : S(T_1')\) and \(\ldots \) and \(S(\varGamma _n) \vdash _{\cap G}S(e_2) : S(T_n')\). Since, by Lemma 9, \(S(\varGamma + \varGamma _1 + \ldots + \varGamma _n) \vdash _{\cap G}S(e_1) : S(T_1 \cap \ldots \cap T_n) \rightarrow S(T)\), \(S(\varGamma + \varGamma _1 + \ldots + \varGamma _n) \vdash _{\cap G}S(e_2) : S(T_1')\) and \(\ldots \) and \(S(\varGamma + \varGamma _1 + \ldots + \varGamma _n) \vdash _{\cap G}S(e_2) : S(T_n')\), then by rule T-App, \(S(\varGamma + \varGamma _1 + \ldots + \varGamma _n) \vdash _{\cap G}S(e_1\ e_2) : S(T)\).

Lemma 10

(Consistent Subtyping to Subtyping). If \(T_1 \lesssim T_2\) and both \(T_1\) and \(T_2\) are static, then \(T_1 \le T_2\).

Proof

We proceed by induction on Definition 2.

Base cases:

  • \(T \lesssim T\). If \(T \lesssim T\) then \(T \le T\).

  • \(T_1 \cap \ldots \cap T_n \lesssim T_1\) and \(\ldots \) and \(T_1 \cap \ldots \cap T_n \lesssim T_n\). If \(T_1 \cap \ldots \cap T_n \lesssim T_1\) and \(\ldots \) and \(T_1 \cap \ldots \cap T_n \lesssim T_n\), then \(T_1 \cap \ldots \cap T_n \le T_1\) and \(\ldots \) and \(T_1 \cap \ldots \cap T_n \le T_n\).

  • \((T \rightarrow T_1) \cap \ldots \cap (T \rightarrow T_n) \lesssim T \rightarrow T_1 \cap \ldots \cap T_n\). If \((T \rightarrow T_1) \cap \ldots \cap (T \rightarrow T_n) \lesssim T \rightarrow T_1 \cap \ldots \cap T_n\) then \((T \rightarrow T_1) \cap \ldots \cap (T \rightarrow T_n) \le T \rightarrow T_1 \cap \ldots \cap T_n\).

Induction step:

  • \(T_1 \rightarrow T_2 \lesssim T_3 \rightarrow T_4 \iff T_3 \lesssim T_1 \wedge T_2 \lesssim T_4\). There are two possibilities:

    • We proceed first for the right direction of the implication. If \(T_1 \rightarrow T_2 \lesssim T_3 \rightarrow T_4\) then \(T_3 \lesssim T_1\) and \(T_2 \lesssim T_4\). By the induction hypothesis, \(T_3 \le T_1\) and \(T_2 \le T_4\). Then by the Definition 1, \(T_1 \rightarrow T_2 \le T_3 \rightarrow T_4\).

    • We now proceed for the left direction of the implication. If \(T_3 \lesssim T_1\) and \(T_2 \lesssim T_4\) then \(T_1 \rightarrow T_2 \lesssim T_3 \rightarrow T_4\). By the induction hypothesis, \(T_1 \rightarrow T_2 \le T_3 \rightarrow T_4\). By Definition 1, \(T_3 \le T_1\) and \(T_2 \le T_4\).

  • \(T \lesssim T_1 \cap \ldots \cap T_n \iff T \lesssim T_1 \wedge \ldots \wedge T \lesssim T_n\). There are two possibilities:

    • We proceed first for the right direction of the implication. If \(T \lesssim T_1 \cap \ldots \cap T_n\) then \(T \lesssim T_1\) and \(\ldots \) and \(T \lesssim T_n\). By the induction hypothesis, \(T \le T_1\) and \(\ldots \) and \(T \le T_n\). Therefore, by Definition 1, \(T \le T_1 \cap \ldots \cap T_n\).

    • We now proceed for the left direction of intersection types. If \(T \lesssim T_1\) and \(\ldots \) and \(T \lesssim T_n\) then \(T \lesssim T_1 \cap \ldots \cap T_n\). By the induction hypothesis, \(T \le T_1 \cap \ldots \cap T_n\). By Definition 1, \(T \le T_1\) and \(\ldots \) and \(T \le T_n\).

Lemma 2 (Constraint Completeness). If \(\varGamma _1 \vdash _{\cap G}e : T_1\) then

  1. 1.

    there exists a derivation \(A\ |\ \varGamma _2 \vdash _{\cap G}e : T_2\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\)

  2. 2.

    for \(A\ |\ \varGamma _{21} \vdash _{\cap G}e : T_{21}\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and \(\ldots \) and \(A\ |\ \varGamma _{2n} \vdash _{\cap G}e : T_{2n}\ |\ C_n\) such that \(\exists S_n\ .\ S_n\,\models \,C_n\) then

    1. (a)

      for each \(x \in dom(\varGamma _1) \cap dom(\textstyle \sum _{i=1}^{n} \varGamma _{2i})\) , \(\varGamma _1(x) \le S_i(\varGamma _{2i}(x))\) , \(\forall i \in 1..n\)

    2. (b)

      \(\textstyle \bigcap _{i=1}^{n} S_i(T_{2i}) \le T_1\)

Proof

We proceed by induction on the length of the derivation tree of \(\varGamma _1 \vdash _{\cap G}e : T_1\).

Base cases:

  • Rule T-Var. If \(\varGamma _1 \vdash _{\cap G}x : T_i\) then \(x : T_1 \cap \ldots \cap T_n \in \varGamma _1\). There are two possibilities:

    • \(x \in dom(A)\). If \(x \in dom(A)\), then \(x : T_1 \cap \ldots \cap T_n \in A\), since the type \(T_1 \cap \ldots \cap T_n\) came from the annotation of the lambda abstraction that binds x. To prove 1., we have that \(A\ |\ \{x : T_1\} \vdash _{\cap G}x : T_1\ |\ \emptyset \) and for a \(S_1 = []\), \(S_1\,\models \,\emptyset \) and \(\ldots \) and \(A\ |\ \{x : T_n\} \vdash _{\cap G}x : T_n\ |\ \emptyset \) and for a \(S_n = []\), \(S_n\,\models \,\emptyset \). To prove 2.a), we have that since \(S_1(\varGamma _{21}(x)) = T_1\) and \(\ldots \) and \(S_n(\varGamma _{2n}(x)) = T_n\) and \(\varGamma _1(x) = T_1 \cap \ldots \cap T_n\) then by Definition 1, \(\varGamma _1(x) \le S_1(\varGamma _{21}(x))\) and \(\ldots \) and \(\varGamma _1(x) \le S_n(\varGamma _ {2n}(x))\) and to prove 2.b), we have that \(S_1(T_1) \cap \ldots \cap S_n(T_n) \le T_i\).

    • \(x \not \in dom(A)\). To prove 1., we have that \(A\ |\ \{x : X_1\} \vdash _{\cap G}x : X_1\ |\ \emptyset \) and for a \(S_1 = [X_1 \mapsto T_1]\), \(S_1\,\models \,\emptyset \) and \(\ldots \) and \(A\ |\ \{x : X_n\} \vdash _{\cap G}x : X_n\ |\ \emptyset \) and for a \(S_n = [X_n \mapsto T_n]\), \(S_n\,\models \,\emptyset \). To prove 2.a), since \(S_1(\varGamma _{21}(x)) = T_1\) and \(\ldots \) and \(S_n(\varGamma _{2n}(x)) = T_n\) and \(\varGamma _1(x) = T_1 \cap \ldots \cap T_n\) then by Definition 1, \(\varGamma _1(x) \le S_1(\varGamma _{21}(x))\) and \(\ldots \) and \(\varGamma _1(x) \le S_n(\varGamma _ {2n}(x))\) and to prove 2.b), we have that \(S_1(X_1) \cap \ldots \cap S_n(X_n) \le T_i\).

  • Rule T-Const. If \(\varGamma \vdash _{\cap G}c : T\), then c is an constant of type T. Therefore, to prove 1., we have that \(A\ |\ \{\} \vdash _{\cap G}c : T\ |\ \{\}\) and \(S\,\models \,\emptyset \). Since there is no \(x \in dom(\varGamma _1) \cap dom(\{\})\), 2.a) is proved. To prove 2.b), we have that \(S(T) \le T\), by Definition 1.

Induction step:

  • Rule T-Abs. If \(\varGamma _1 \vdash _{\cap G}\lambda x\ .\ e : T_1 \rightarrow T_2\) then \(\varGamma _1, x : T_1 \vdash _{\cap G}e : T_2\). There are two possibilities:

    • \(x \in dom(\varGamma _2)\). By the induction hypothesis on 1., exists \(A\ |\ \varGamma _2 \vdash _{\cap G}e : T_2'\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\).

      By the induction hypothesis on 2., we have that for \(A\ |\ \varGamma _{21} \vdash _{\cap G}e : T_{21}\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and \(\ldots \) and for \(A\ |\ \varGamma _{2n} \vdash _{\cap G}e : T_{2n}\ |\ C_n\) such that \(\exists S_n\ .\ S_n\,\models \,C_n\), then for each \(y \in dom(\varGamma _1, x : T_1) \cap dom(\textstyle \sum _{i=1}^n \varGamma _{2i})\), we have \((\varGamma _1, x : T_1)(y) \le S_i(\varGamma _{2i}(y))\), \(\forall i \in 1..n\), and \(\textstyle \bigcap _{i=1}^n S_i(T_{2i}) \le T_2\).

      To prove 1., we have that as \(A\ |\ \varGamma _2 \vdash _{\cap G}e : T_2'\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\), then by rule C-Abs1, exists \(A\ |\ \varGamma _{2x} \vdash _{\cap G}\lambda x\ .\ e : \varGamma _{2}(x) \rightarrow T_2'\ |\ C\) and \(S\,\models \,C\).

      To prove 2., we have that for \(A\ |\ \varGamma _{21} \vdash _{\cap G}e : T_{21}\ |\ C_1\) then \(A\ |\ \varGamma _{21x} \vdash _{\cap G}\lambda x\ .\ e : \varGamma _{21}(x) \rightarrow T_{21}\ |\ C_1\) and \(S_1\,\models \,C_1\) and \(\ldots \) and for \(A\ |\ \varGamma _{2n} \vdash _{\cap G}e : T_{2n}\ |\ C_n\) then \(A\ |\ \varGamma _{2nx} \vdash _{\cap G}\lambda x\ .\ e : \varGamma _{2n}(x) \rightarrow T_{2n}\ |\ C_n\) and \(S_n\,\models \,C_n\).

      To prove 2.a), as \((\varGamma _1, x : T_1)(y) \le S_1(\varGamma _{21}(y))\) and \(\ldots \) and \((\varGamma _1, x : T_1)(y) \le S_n(\varGamma _{2n}(y))\) for each \(y \in dom(\varGamma _1, x : T_1) \cap dom(\varGamma _2)\) then \((\varGamma _1)(y) \le S_1(\varGamma _{21x}(y))\) and \(\ldots \) and \((\varGamma _1)(y) \le S_n(\varGamma _{2nx}(y))\).

      To prove 2.b), as \(S_1(T_{21}) \cap \ldots \cap S_n(T_{2n}) \le T_2\) and \(T_1 \le S_1(\varGamma _{21}(x))\) and \(\ldots \) and \(T_1 \le S_n(\varGamma _{2n}(x))\) then by Definition 1, rule 4, \(T_1 \le S_1(\varGamma _{21}(x)) \cap \ldots \cap S_n(\varGamma _{2n}(x))\). Therefore, by Definition 1, rule 3, \(S_1(\varGamma _{21}(x)) \cap \ldots \cap S_n(\varGamma _{2n}(x)) \rightarrow S_1(T_{21}) \cap \ldots \cap S_n(T_{2n}) \le T_1 \rightarrow T_2\). Therefore, by Definition 1, rule 5, \((S_1(\varGamma _{21}(x)) \cap \ldots \cap S_n(\varGamma _{2n}(x)) \rightarrow S_1(T_{21})) \cap \ldots \cap (S_1(\varGamma _{21}(x)) \cap \ldots \cap S_n(\varGamma _{2n}(x)) \rightarrow S_n(T_{2n})) \le T_1 \rightarrow T_2\). By Definition 1, rule 2, \(S_1(\varGamma _{21}(x) \rightarrow T_{21}) \cap \ldots \cap S_n(\varGamma _{2n}(x) \rightarrow T_{2n}) \le T_1 \rightarrow T_2\).

    • \(x \not \in dom(\varGamma _2)\). By the induction hypothesis on 1., exists \(A\ |\ \varGamma _2 \vdash _{\cap G}e : T_2'\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\).

      By the induction hypothesis on 2., we have that for \(A\ |\ \varGamma _{21} \vdash _{\cap G}e : T_{21}\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and \(\ldots \) and for \(A\ |\ \varGamma _{2n} \vdash _{\cap G}e : T_{2n}\ |\ C_n\) such that \(\exists S_n\ .\ S_n\,\models \,C_n\) then for each \(y \in dom(\varGamma _1, x : T_1) \cap dom(\textstyle \sum _{i=1}^n \varGamma _{2i})\), we have \((\varGamma _1, x : T_1)(y) \le S_i(\varGamma _{2i}(y))\), \(\forall i \in 1..n\) and \(\textstyle \bigcap {i=1}^n S_i(T_{2i}) \le T_2\).

      To prove 1., we have that as \(A\ |\ \varGamma _2 \vdash _{\cap G}e : T_2'\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\) then by rule C-Abs2, exists \(A\ |\ \varGamma _2 \vdash _{\cap G}\lambda x\ .\ e : X \rightarrow T_2'\ |\ C\) and \(S\,\models \,C\).

      To prove 2., we have that for \(A\ |\ \varGamma _{21} \vdash _{\cap G}e : T_{21}\ |\ C_1\) then \(A\ |\ \varGamma _{21} \vdash _{\cap G}\lambda x\ .\ e : X_1 \rightarrow T_{21}\ |\ C_1\) and \(S_1\,\models \,C_1\) and \(\ldots \) and for \(A\ |\ \varGamma _{2n} \vdash _{\cap G}e : T_{2n}\ |\ C_n\) then \(A\ |\ \varGamma _{2n} \vdash _{\cap G}\lambda x\ .\ e : X_n \rightarrow T_{2n}\ |\ C_n\) and \(S_n\,\models \,C_n\).

      Since \(X_1\) is a fresh type variable, it is not contained in \(C_1\) and \(\ldots \) and since \(X_n\) is a fresh type variable, it is not contained in \(C_n\). Then, we can consider \(S_1 = S_1' \circ [X_1 \mapsto T_1]\) and \(\ldots \) and we can consider \(S_n = S_n' \circ [X_n \mapsto T_1]\).

      To prove 2.a), as for each \(y \in dom(\varGamma _1, x : T_1) \cap dom(\textstyle \sum _{i=1}^n \varGamma _{2i})\), we have \((\varGamma _1, x : T_1)(y) \le S_i(\varGamma _{2i}(y))\), \(\forall i \in 1..n\), then \(\varGamma _1(y) \le S_i(\varGamma _{2ix}(y))\), \(\forall i \in 1..n\).

      To prove 2.b), as \(T_1 \le S_1(X_1)\) and \(\ldots \) and \(T_1 \le S_n(X_n)\) then by Definition 1, rule 4, \(T_1 \le S_1(X_1) \cap \ldots \cap S_n(X_n)\). As \(S_1(T_{21}) \cap \ldots \cap S_n(T_{2n}) \le T_2\), then by Definition 1, rule 3, \(S_1(X_1) \cap \ldots \cap S_n(X_n) \rightarrow S_1(T_{21}) \cap \ldots \cap S_n(T_{2n}) \le T_1 \rightarrow T_2\). Therefore, by Definition 1, rule 5, \((S_1(X_1) \cap \ldots \cap S_n(X_n) \rightarrow S_1(T_{21})) \cap \ldots \cap (S_1(X_1) \cap \ldots \cap S_n(X_n) \rightarrow S_n(T_{2n})) \le T_1 \rightarrow T_2\). By Definition 1, rule 2, \(S_1(X_1 \rightarrow T_{21}) \cap \ldots \cap S_n(X_n \rightarrow T_{2n}) \le T_1 \rightarrow T_2\).

  • Rule T-Abs. If \(\varGamma _1 \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : T_1 \cap \ldots \cap T_m \rightarrow T\) then \(\varGamma _1, x : T_1 \cap \ldots \cap T_m \vdash _{\cap G}e : T\). There are two possibilities:

    • \(x \in dom(\varGamma _2)\). By the induction hypothesis on 1., exists \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _2 \vdash _{\cap G}e : T'\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\).

      By the induction hypothesis on 2., we have that for \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _{21} \vdash _{\cap G}e : T_1'\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and \(\ldots \) and for \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _{2l} \vdash _{\cap G}e : T_l'\ |\ C_l\) such that \(\exists S_l\ .\ S_l\,\models \,C_l\) then for each \(y \in dom(\varGamma _1, x : T_1 \cap \ldots \cap T_m) \cap dom(\textstyle \sum _{i=1}^l \varGamma _{2i})\), we have that \((\varGamma _1, x : T_1 \cap \ldots \cap T_m)(y) \le S_i(\varGamma _{2i}(y))\), \(\forall i \in 1..l\), and \(\textstyle \bigcap _{i=1}^l S_i(T_i') \le T\).

      To prove 1., we have that as \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _2 \vdash _{\cap G}e : T'\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\), then \(A\ |\ \varGamma _{2x} \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : \varGamma _{2}(x) \rightarrow T'\ |\ C\) and \(S\,\models \,C\).

      To prove 2., we have that for \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _{21} \vdash _{\cap G}e : T_1'\ |\ C_1\) then \(A\ |\ \varGamma _{21x} \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : \varGamma _{21}(x) \rightarrow T_1'\ |\ C_1\) and \(S_1\,\models \,C_1\) and \(\ldots \) and for \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _{2l} \vdash _{\cap G}e : T_l'\ |\ C_l\) then \(A\ |\ \varGamma _{2lx} \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : \varGamma _{2l}(x) \rightarrow T_l'\ |\ C_l\) and \(S_l\,\models \,C_l\).

      To prove 2.a), as for each \(y \in dom(\varGamma _1) \cap dom(\textstyle \sum _{i=1}^l \varGamma _{2i})\), we have \((\varGamma _1, x : T_1 \cap \ldots \cap T_m)(y) \le S_i(\varGamma _{2i}(y))\), \(\forall i \in 1..l\), then \(\varGamma _1(y) \le S_i(\varGamma _{2ix}(y))\).

      To prove 2.b), we have that \(T_1 \cap \ldots \cap T_m \le S_1(\varGamma _{21}(x))\) and \(\ldots \) and \(T_1 \cap \ldots \cap T_m \le S_l(\varGamma _{2l}(x))\). As \(T_1 \cap \ldots \cap T_m \le S_1(\varGamma _{21}(x))\) and \(\ldots \) and \(T_1 \cap \ldots \cap T_m \le S_l(\varGamma _{2l}(x))\) then by Definition 1, rule 4, \(T_1 \cap \ldots \cap T_m \le S_1(\varGamma _{21}(x)) \cap \ldots \cap S_l(\varGamma _{2l}(x))\). As \(S_1(T_1') \cap \ldots \cap S_l(T_l') \le T\), then by Definition 1, rule 3, \(S_1(\varGamma _{21}(x)) \cap \ldots \cap S_l(\varGamma _{2l}(x)) \rightarrow S_1(T_1') \cap \ldots \cap S_l(T_l') \le T_1 \cap \ldots \cap T_m \rightarrow T\). Therefore, by Definition 1, rule 5, \((S_1(\varGamma _{21}(x)) \cap \ldots \cap S_l(\varGamma _{2l}(x)) \rightarrow S_1(T_1')) \cap \ldots \cap (S_1(\varGamma _{21}(x)) \cap \ldots \cap S_l(\varGamma _{2l}(x)) \rightarrow S_l(T_l')) \le T_1 \cap \ldots \cap T_m \rightarrow T\). By Definition 1, rule 2, \(S_1(\varGamma _{21}(x) \rightarrow T_1') \cap \ldots \cap S_l(\varGamma _{2l}(x) \rightarrow T_l') \le T_1 \cap \ldots \cap T_m \rightarrow T\).

    • \(x \not \in dom(\varGamma _2)\). By the induction hypothesis on 1., exists \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _2 \vdash _{\cap G}e : T'\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\).

      By the induction hypothesis on 2., we have that for \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _{21} \vdash _{\cap G}e : T_1'\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and \(\ldots \) and for \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _{2l} \vdash _{\cap G}e : T_l'\ |\ C_l\) such that \(\exists S_l\ .\ S_l\,\models \,C_l\) then for each \(y \in dom(\varGamma _1, x : T_1 \cap \ldots \cap T_m) \cap dom(\textstyle \sum _{i=1}^l \varGamma _{2i})\), we have that \((\varGamma _1, x : T_1 \cap \ldots \cap T_m)(y) \le S_i(\varGamma _{2i}(y))\), \(\forall i \in 1..l\), and \(\textstyle \bigcap _{i=1}^l S_i(T_i') \le T\).

      To prove 1., we have that as \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _2 \vdash _{\cap G}e : T'\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\) then by rule C-Abs:2, exists \(A\ |\ \varGamma _2 \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : T_1 \rightarrow T' \cap \ldots \cap T_n \rightarrow T'\ |\ C\) and \(S\,\models \,C\).

      To prove 2., we have that for \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _{21} \vdash _{\cap G}e : T_1'\ |\ C_1\) then \(A\ |\ \varGamma _{21} \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : T_1 \rightarrow T_1' \cap \ldots \cap T_n \rightarrow T_1'\ |\ C_1\) and \(S_1\,\models \,C_1\) and \(\ldots \) and for \(A_x \cup \{x : T_1 \cap \ldots \cap T_n\}\ |\ \varGamma _{2l} \vdash _{\cap G}e : T_l'\ |\ C_l\) then \(A\ |\ \varGamma _{2l} \vdash _{\cap G}\lambda x : T_1 \cap \ldots \cap T_n\ .\ e : T_1 \rightarrow T_l' \cap \ldots \cap T_n \rightarrow T_l'\ |\ C_l\) and \(S_n\,\models \,C_n\).

      To prove 2.a), as for each \(y \in dom(\varGamma _1, x : T_1 \cap \ldots \cap T_m) \cap dom(\textstyle \sum _{i=1}^l \varGamma _{2i})\), we have that \((\varGamma _1, x : T_1 \cap \ldots \cap T_m)(y) \le S_i(\varGamma _{2i}(y))\), \(\forall i \in 1..l\), then \(\varGamma _1(y) \le S_i(\varGamma _{2i}(y))\).

      To prove 2.b), as x does not occur in e, then \(T_1\) and \(\ldots \) and \(T_n\) are not affected by \(S_1, \ldots , S_n\). Therefore \(S_1(T_1 \cap \ldots \cap T_n) = T_1 \cap \ldots \cap T_n\) and \(\ldots \) and \(S_l(T_1 \cap \ldots \cap T_n) = T_1 \cap \ldots \cap T_n\). Therefore, \(S_1((T_1 \rightarrow T_1') \cap \ldots \cap (T_n \rightarrow T_1')) \cap \ldots \cap S_l((T_1 \rightarrow T_l') \cap \ldots \cap (T_n \rightarrow T_l')) = (T_1 \rightarrow S_1(T_1')) \cap \ldots \cap (T_n \rightarrow S_1(T_1')) \cap \ldots \cap (T_1 \rightarrow S_l(T_l')) \cap \ldots \cap (T_n \rightarrow S_l(T_l'))\). Then, by Definition 1, rule 2, \((T_1 \rightarrow S_1(T_1')) \cap \ldots \cap (T_n \rightarrow S_1(T_1')) \cap \ldots \cap (T_1 \rightarrow S_l(T_l')) \cap \ldots \cap (T_n \rightarrow S_l(T_l')) \le (T_1 \cap \ldots \cap T_m \rightarrow S_1(T_1')) \cap \ldots \cap (T_1 \cap \ldots \cap T_m \rightarrow S_l(T_l'))\). Then, by Definition 1, rule 5, \((T_1 \cap \ldots \cap T_m \rightarrow S_1(T_1')) \cap \ldots \cap (T_1 \cap \ldots \cap T_m \rightarrow S_l(T_l')) \le T_1 \cap \ldots \cap T_m \rightarrow S_1(T_1') \cap \ldots \cap S_l(T_l')\). Then, by Definition 1, rule 3, \(T_1 \cap \ldots \cap T_m \rightarrow S_1(T_1') \cap \ldots \cap S_l(T_l') \le T_1 \cap \ldots \cap T_m \rightarrow T\).

  • Rule T-App. If \(\varGamma \vdash _{\cap G}e_1\ e_2 : T\) then \(\varGamma \vdash _{\cap G}e_1 : PM\), \(PM \rhd T_1 \cap \ldots \cap T_n \rightarrow T\), \(\varGamma \vdash _{\cap G}e_2 : T_1' \cap \ldots \cap T_n'\) and \(T_1' \lesssim T_1\) and \(\ldots \) and \(T_n' \lesssim T_n\). There are two possibilities:

    • Using rule C-App. By the induction hypothesis on 1., exists \(A\ |\ \varGamma _1 \vdash _{\cap G}e_1 : PM'\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and exists \(A\ |\ \varGamma _2 \vdash _{\cap G}e_2 : T''\ |\ C_2\) such that \(\exists S_2\ .\ S_2\,\models \,C_2\).

      By the induction hypothesis on 2., we have that for \(A\ |\ \varGamma _{11} \vdash _{\cap G}e_1 : PM_1\ |\ C_{11}\) such that \(\exists S_{11}\ .\ S_{11}\,\models \,C_{11}\) and \(\ldots \) and \(A\ |\ \varGamma _{1n'} \vdash _{\cap G}e_1 : PM_{1n'}\ |\ C_{1n'}\) such that \(\exists S_{1n'}\ .\ S_{1n'}\,\models \,C_{1n'}\) then for each \(x \in dom(\varGamma ) \cap dom(\textstyle \sum _{i=1}^{n'} \varGamma _{1i})\), we have that \(\varGamma (x) \le S_{1i}(\varGamma _{1i}(x))\) and \(\textstyle \bigcap _{i=1}^{n'} S_{1i}(PM_i) \le PM\).

      Also, by the induction hypothesis on 2., we have that for \(A\ |\ \varGamma _{21} \vdash _{\cap G}e_2 : T_{1}''\ |\ C_{21}\) such that \(\exists S_{21}\ .\ S_{21}\,\models \,C_{21}\) and \(\ldots \) and \(A\ |\ \varGamma _{2m'} \vdash _{\cap G}e_2 : T_{m'}''\ |\ C_{2m'}\) such that \(\exists S_{2m'}\ .\ S_{2m'}\,\models \,C_{2m'}\) then for each \(x \in dom(\varGamma ) \cap dom(\textstyle \sum _{j=1}^{m'} \varGamma _{2j})\), we have that \(\varGamma (x) \le S_{2j}(\varGamma _{2j}(x))\) and \(\textstyle \bigcap _{j=1}^{m'} S_{2j}(T_j'') \le T_1' \cap \ldots \cap T_n'\).

      To prove 1., we want to prove that since \(A\ |\ \varGamma _1 \vdash _{\cap G}e_1 : PM'\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and since \(A\ |\ \varGamma _2 \vdash _{\cap G}e_2 : T''\ |\ C_2\) such that \(\exists S_2\ .\ S_2\,\models \,C_2\), and for \(cod(PM') \doteq T_3\ |\ C_3\) and \(T''\ \dot{\lesssim }\ dom(PM')\ |\ C_4\), then exists \(A\ |\ \varGamma _1 + \varGamma _2 \vdash _{\cap G}e_1\ e_2 : T_3\ |\ C_1 \cup C_2 \cup C_3 \cup C_4\) such that \(\exists S_k\ .\ S_k\,\models \,C_1 \cup C_2 \cup C_3 \cup C_4\).

      To prove 2., we want to prove that, for \(\forall i \in 1..n'\) and \(\forall j \in 1..m'\) such that \(A\ |\ \varGamma _{1i} \vdash _{\cap G}e_1 : PM_i\ |\ C_{1i}\) such that \(\exists S_{1i}\ .\ S_{1i}\,\models \,C_{1i}\), \(A\ |\ \varGamma _{2j} \vdash _{\cap G}e_2 : T_{j}''\ |\ C_{2j}\) such that \(\exists S_{2j}\ .\ S_{j2}\,\models \,C_{2j}\), \(cod(PM_i) \doteq T_{3i}\ |\ C_{3i}\) and \(T_{j}''\ \dot{\lesssim }\ dom(PM_i)\ |\ C_{4k}\), with \(k \in 1..i*j\) then for \(A\ |\ \varGamma _{1i} + \varGamma _{2j} \vdash _{\cap G}e_1\ e_2 : T_{3i}\ |\ C_{1i} \cup C_{2j} \cup C_{3i} \cup C_{4k}\), such that \(\exists S_k\ .\ S_k\,\models \,C_{1i} \cup C_{2j} \cup C_{3i} \cup C_{4k}\) then 2.a) for each \(x \in dom(\varGamma ) \cap dom(\varGamma _{1i} + \varGamma _{2j})\) we have that \(\varGamma (x) \le S_k(\varGamma _{1i} + \varGamma _{2j})(x)\), and 2.b) \(S_1(T_{13}) \cap \ldots \cap S_{n'*m'}(T_{n'3}) \le T\). We define \(dom_{\rhd }\) as \(dom_{\rhd }({ Dyn }) = { Dyn }\) and \(dom_{\rhd }(T_1 \rightarrow T_2) = T_1\) and \(cod_{\rhd }\) as \(cod_{\rhd }({ Dyn }) = { Dyn }\) and \(cod_{\rhd }(T_1 \rightarrow T_2) = T_2\). Since \(cod_{\rhd }(PM) = T\), we want to prove that \(S_k(T_{i3}) \le cod_{\rhd }(S_{i1}(PM_i))\).

      By Definition 1, rule 4, we have that \(\varGamma (x) \le (S_{1i}(\varGamma _{1i}) + S_{2j}(\varGamma _{2j}))(x)\). Since substitutions in \(S_{1i}\) don’t affect \(\varGamma _{2j}\) and substitutions in \(S_{2j}\) don’t affect \(\varGamma _{1i}\), then \(\varGamma (x) \le (S_{1i} \circ S_{2j}(\varGamma _{1i} + \varGamma _{2j}))(x)\). For an \(S_{3i}\,\models \,C_{3i}\) and \(S_{4k}\,\models \,C_{4k}\), \(S_{3i}\) doesn’t affect \(S_{2j}\). There are 3 possibilities:

      *:

      \(PM_i = X\). Proof for 1. We have that exists \(A\ |\ \varGamma _1 \vdash _{\cap G}e_1 : PM'\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and exists \(A\ |\ \varGamma _2 \vdash _{\cap G}e_2 : T''\ |\ C_2\) such that \(\exists S_2\ .\ S_2\,\models \,C_2\), and for \(cod(X) \doteq X_2\ |\ \{X \doteq X_1 \rightarrow X_2\}\) and \(T''\ \dot{\lesssim }\ dom(PM')\ |\ \{X \doteq X_3 \rightarrow X_4, T''\ \dot{\lesssim }\ X_3\}\) then, by rule C-App, \(A\ |\ \varGamma _1 + \varGamma _2 \vdash _{\cap G}e_1\ e_2 : T_3\ |\ C_1 \cup C_2 \cup \{X \doteq X_1 \rightarrow X_2\} \cup \{X \doteq X_3 \rightarrow X_4, T''\ \dot{\lesssim }\ X_3\}\). We now have to prove that \(\exists S\ .\ S\,\models \,C_1 \cup C_2 \cup \{X \doteq X_1 \rightarrow X_2\} \cup \{X \doteq X_3 \rightarrow X_4, T''\ \dot{\lesssim }\ X_3\}\). Since \(S_2(T'') \le T_1' \cap \ldots \cap T_n'\), and \(T_1' \lesssim T_1\) and \(\ldots \) and \(T_n' \lesssim T_n\) and \(T_1 \cap \ldots \cap T_n \le dom_{\rhd } S_1(PM')\), then \(S_2(T'') \lesssim dom_{\rhd }(S_1(PM'))\). Therefore, it is proved.

      Proof for 2. For all \(i \in 1..n'\), \(j \in 1..m'\), such that \(A\ |\ \varGamma _{1i} \vdash _{\cap G}e_1 : PM_i\ |\ C_{1i}\) and \(\exists S_{1i}\ .\ S_{1i}\,\models \,C_{1i}\), \(A\ |\ \varGamma _{2j} \vdash _{\cap G}e_2 : T_{j}''\ |\ C_{2j}\) and \(\exists S_{2j}\ .\ S_{2j}\,\models \,C_{2j}\), \(cod(PM_i) \doteq T_{3i}\ |\ C_{3i}\) and \(T_{j}''\ \dot{\lesssim }\ dom(PM_i)\ |\ C_{4k}\), then \(A\ |\ \varGamma _{1i} + \varGamma _{2j} \vdash _{\cap G}e_1\ e_2 : T_{3i}\ |\ C_{1i} \cup C_{2j} \cup C_{3i} \cup C_{4k}\), with \(k \in 1 .. i*j\).

      Since \(PM_i\) is a type variable, then there exists a term variable x such that \(PM_i = \varGamma _{1i}(x)\) and so we have that \(C_{3i} = \{X \doteq X_1 \rightarrow X_2\}\) and \(C_{k4} = \{X \doteq X_3 \rightarrow X_4, T_j''\ \dot{\lesssim }\ X_3\}\). As \(\varGamma (x) \le S_{1i}(X)\) and, since we are dealing with an expression application, \(\varGamma (x) = T_1 \rightarrow T\) for some simple types \(T_1\) and T, then \(T_1 \rightarrow T \le S_{1i}(X)\). Since substitutions don’t introduce intersection types, then \(T_1 \rightarrow T = S_{1i}(X)\).

      Proof for 2.a). If \(S_k\,\models \,T_j''\ \dot{\lesssim }\ X_3\), then by Definition 3, \(S_k(T_j'') \lesssim S_k(X_3)\). If \(T_j'' \in cod(S_{2j}(\varGamma _{2j}))\) and \(T_j''\) is static, then \(S_{2j}(\varGamma _{2j})(x) \le S_k(\varGamma _{2j})(x)\). Also, since \(X \in cod(S_{i1}(\varGamma _{i1}))\), then \(S_{i1}(\varGamma _{i1}) \le S_k(\varGamma _{i1})\). For a \(S_k\) such that \(S_k\,\models \,C_{i1} \cup C_{j2} \cup C_{i3} \cup C_{k4}\), \(\varGamma (x) \le S_k(\varGamma _{i1} + \varGamma _{j2})(x)\).

      Proof for 2.b). We have that \(T = cod_{\rhd }(S_{i1}(PM_i))\) and \(S_k(T_{i3}) = T\).

      *:

      \(PM_i = T_3 \rightarrow T_4\). We have that exists \(A\ |\ \varGamma _1 \vdash _{\cap G}e_1 : PM'\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and exists \(A\ |\ \varGamma _2 \vdash _{\cap G}e_2 : T''\ |\ C_2\) such that \(\exists S_2\ .\ S_2\,\models \,C_2\), and for \(cod(T_3 \rightarrow T_4) \doteq T_4\ |\ \{\}\) and \(T''\ \dot{\lesssim }\ dom(T_3 \rightarrow T_4)\ |\ \{T''\ \dot{\lesssim }\ T_3\}\) then, by rule C-App, \(A\ |\ \varGamma _1 + \varGamma _2 \vdash _{\cap G}e_1\ e_2 : T_4\ |\ C_1 \cup C_2 \cup \{T''\ \dot{\lesssim }\ T_3\}\). We now have to prove that \(\exists S\ .\ S\,\models \,C_1 \cup C_2 \cup \{T''\ \dot{\lesssim }\ T_3\}\). Since \(S_2(T'') \le T_1' \cap \ldots \cap T_n'\), and \(T_1' \lesssim T_1\) and \(\ldots \) and \(T_n' \lesssim T_n\) and \(T_1 \cap \ldots \cap T_n \le S_1(T_3)\), then \(S_2(T'') \lesssim S_1(T_3)\). Therefore, it is proved.

      For all \(i \in 1..n'\), \(j \in 1..m'\), such that \(A\ |\ \varGamma _{1i} \vdash _{\cap G}e_1 : PM_i\ |\ C_{1i}\) and \(\exists S_{1i}\ .\ S_{1i}\,\models \,C_{1i}\), \(A\ |\ \varGamma _{2j} \vdash _{\cap G}e_2 : T_{j}''\ |\ C_{2j}\) and \(\exists S_{2j}\ .\ S_{2j}\,\models \,C_{2j}\), \(cod(PM_i) \doteq T_{3i}\ |\ C_{3i}\) and \(T_{j}''\ \dot{\lesssim }\ dom(PM_i)\ |\ C_{4k}\), then \(A\ |\ \varGamma _{1i} + \varGamma _{2j} \vdash _{\cap G}e_1\ e_2 : T_{3i}\ |\ C_{1i} \cup C_{2j} \cup C_{3i} \cup C_{4k}\), with \(k \in 1 .. i*j\).

      Proof for 2.a). \(S_{i3}\) doesn’t affect \(\varGamma _{i1}\) and \(\varGamma _{j2}\). We don’t allow variables in annotations in lambda abstractions. If \(T_3 = { Dyn }\) or \(T_j'' = { Dyn }\) then \([]\,\models \,T_j''\ \dot{\lesssim }\ T_3\) and so, \(\varGamma (x) \le S_k(\varGamma _{i1} + \varGamma _{j2})(x)\). One way that \(PM_i = T_3 \rightarrow T_4\) is if \(e_1\) is a term variable and \(T_3\) is a type variable, and so \(T_3 \not \in \varGamma _{i1}\) then \(\varGamma (x) \le S_k(\varGamma _{i1} + \varGamma _{j2})(x)\). Another way that \(PM_i = T_3 \rightarrow T_4\) is if \(e_1\) is a lambda abstraction and \(T_3 \rightarrow T_4 \in \varGamma _{i1}\), and so \(T_3\) is not a type variable, then \(\varGamma (x) \le S_k(\varGamma _{i1} + \varGamma _{j2})(x)\). Therefore, if \(T_j'' \in \varGamma _{j2}\), and as \(S_k\,\models \,T_j''\ \dot{\lesssim }\ T_3\) then \(\varGamma (x) \le S_k(\varGamma _{i1} + \varGamma _{j2})(x)\).

      Proof for 2.b). We have that \(T_{i3} = T_4\), then \(cod_{\rhd }(S_{i1}(PM_i)) = S_{i1}(T_{i3})\). We want to prove that \(S_i(T_{i3}) \le S_{i1}(T_{i3})\). If \(T_{i3}\) is not a variable, then \(S_i(T_{i3}) = S_{i1}(T_{i3})\). If \(T_{i3}\) is a variable, then either \(T_{i3} \ne T_3\), in which case \(S_k\) doesn’t affect \(S_{i1}(T_4)\) and so \(S_{i1}(T_4) = S_k(T_4)\). Otherwise, \(T_3 = T_4 = T_{i3}\). Therefore, as \(S_k\,\models \,T_j''\ \dot{\lesssim }\ T_4\). So, \(S_k(T_4) \lesssim S_{i1}(T_4)\). Since \(S_k\) doesn’t have a subtitution that turns \(T_4\) into \({ Dyn }\), then by Lemma 10, \(S_k(T_4) \le S_{i1}(T_4)\).

      *:

      \(PM_i = { Dyn }\). Proof for 1. We have that exists \(A\ |\ \varGamma _1 \vdash _{\cap G}e_1 : { Dyn }\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and exists \(A\ |\ \varGamma _2 \vdash _{\cap G}e_2 : T''\ |\ C_2\) such that \(\exists S_2\ .\ S_2\,\models \,C_2\), and for \(cod({ Dyn }) \doteq { Dyn }\ |\ \{\}\) and \(T''\ \dot{\lesssim }\ dom({ Dyn })\ |\ \{T''\ \dot{\lesssim }\ { Dyn }\}\) then, by rule C-App, \(A\ |\ \varGamma _1 + \varGamma _2 \vdash _{\cap G}e_1\ e_2 : { Dyn }\ |\ C_1 \cup C_2 \cup \{T''\ \dot{\lesssim }\ { Dyn }\}\). Since \(\exists S\ .\ S\,\models \,C_1 \cup C_2 \cup \{T''\ \dot{\lesssim }\ { Dyn }\}\), it is proved.

      Proof for 2. For all \(i \in 1..n'\), \(j \in 1..m'\), such that \(A\ |\ \varGamma _{1i} \vdash _{\cap G}e_1 : PM_i\ |\ C_{1i}\) and \(\exists S_{1i}\ .\ S_{1i}\,\models \,C_{1i}\), \(A\ |\ \varGamma _{2j} \vdash _{\cap G}e_2 : T_{j}''\ |\ C_{2j}\) and \(\exists S_{2j}\ .\ S_{2j}\,\models \,C_{2j}\), \(cod(PM_i) \doteq T_{3i}\ |\ C_{3i}\) and \(T_{j}''\ \dot{\lesssim }\ dom(PM_i)\ |\ C_{4k}\), then \(A\ |\ \varGamma _{1i} + \varGamma _{2j} \vdash _{\cap G}e_1\ e_2 : T_{3i}\ |\ C_{1i} \cup C_{2j} \cup C_{3i} \cup C_{4k}\), with \(k \in 1 .. i*j\).

      Proof for 2.a). For \(A\ |\ \varGamma _{1i} + \varGamma _{2j} \vdash _{\cap G}e_1\ e_2 : T_{3i}\ |\ C_{1i} \cup C_{2j} \cup C_{3i} \cup C_{4k}\), with \(k \in 1 .. i*j\) such that \(S_k\,\models \,C_{1i} \cup C_{2j} \cup C_{3i} \cup C_{4k}\), we have that \(C_{i3} = \{\}\) and \(C_{k4} = \{T_j''\ \dot{\lesssim }\ { Dyn }\}\). Therefore, \(S_k = S_1 \circ S_2\) and then \(\varGamma (x) \le S_k(\varGamma _{i1} + \varGamma _{j2})(x)\).

      Proof for 2.b). We have that \(cod_{\rhd }(S_{i1}(PM_i)) = { Dyn }\) and \(S_i(T_i3) = { Dyn }\).

    • Using rule C-App\(\cap \). By the induction hypothesis on 1., exists \(A\ |\ \varGamma ' \vdash _{\cap G}e_1 : T_1 \cap \ldots \cap T_m \rightarrow T_0\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\) and exists \(A\ |\ \varGamma '' \vdash _{\cap G}e_2 : T''\ |\ C''\) such that \(\exists S''\ .\ S''\,\models \,C''\) and \(\ldots \) and exists \(A\ |\ \varGamma '' \vdash _{\cap G}e_2 : T''\ |\ C''\) such that \(\exists S''\ .\ S''\,\models \,C''\).

      By the induction hypothesis on 2., we have that for \(A\ |\ \varGamma _1 \vdash _{\cap G}e_1 : T_{11} \cap \ldots \cap T_{1{m^1}} \rightarrow T_{10}\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and \(\ldots \) and for \(A\ |\ \varGamma _{n'} \vdash _{\cap G}e_1 : T_{n'1} \cap \ldots \cap T_{n'm^{n'}} \rightarrow T_{n'0}\ |\ C_{n'}\) such that \(\exists S_{n'}\ .\ S_{n'}\,\models \,C_{n'}\) then for each \(x \in dom(\varGamma ) \cap dom(\textstyle \sum _{i=1}^{n'} \varGamma _i)\), we have that \(\varGamma (x) \le S_i(\varGamma _i(x))\) and \(\textstyle \bigcap _{i=1}^{n'} S_i(T_{i1} \cap \ldots \cap T_{i{m^i}} \rightarrow T_{i0}) \le PM\).

      Also, by the induction hypothesis on 2., we have that for \(A\ |\ \varGamma _1' \vdash _{\cap G}e_2 : T_1''\ |\ C_1'\) such that \(\exists S_1'\ .\ S_1'\,\models \,C_1'\) and \(\ldots \) and for \(A\ |\ \varGamma _k' \vdash _{\cap G}e_2 : T_k''\ |\ C_k'\) such that \(\exists S_k'\ .\ S_k'\,\models \,C_k'\) then for each \(x \in dom(\varGamma ) \cap dom(\textstyle \sum _{l=1}^{k} \varGamma _i')\), we have that \(\varGamma (x) \le S_l'(\varGamma _l'(x))\) and \(\textstyle \bigcap _{l=1}^{k} S_l'(T_l'') \le T_1' \cap \ldots \cap T_n'\).

      Proof for 1. If \(S(T_1 \cap \ldots \cap T_m \rightarrow T_0) \le PM\), then by Definition 1 and \(\rhd \), \(PM = T_1 \cap \ldots \cap T_n \rightarrow T\). Therefore, \(T_1 \cap \ldots \cap T_n \le S(T_1 \cap \ldots \cap T_m)\) and \(S(T_0) \le T\). We have that \(S''(T'') \le T_1' \cap \ldots \cap T_n'\) and \(T_1' \lesssim T_1\) and \(\ldots \) and \(T_n' \lesssim T_n\) and \(T_1 \cap \ldots \cap T_n \le S(T_1 \cap \ldots \cap T_m)\). Therefore, we have that \(S''(T'') \lesssim S(T_1)\) and \(\ldots \) and \(S''(T'') \lesssim S(T_m)\). Therefore, we have that \(A\ |\ \varGamma ' + \varGamma '' + \ldots + \varGamma '' \vdash _{\cap G}e_1\ e_2 : T_0\ |\ C \cup C'' \cup \{T''\ \dot{\lesssim }\ T_1\} \cup \ldots \cup C'' \cup \{T''\ \dot{\lesssim }\ T_m\}\) such that \(S \circ S'' \circ \ldots \circ S''\,\models \,C \cup C'' \cup \{T''\ \dot{\lesssim }\ T_1\} \cup \ldots \cup C'' \cup \{T''\ \dot{\lesssim }\ T_m\}\).

      Proof for 2. For all \(i \in 1..n'\), \(j \in 1 .. m^i\), \(l, l' \in 1 .. k\), such that \(A\ |\ \varGamma _i \vdash _{\cap G}e_1 : T_{i1} \cap \ldots \cap T_{i{m^i}} \rightarrow T_{i0}\ |\ C_i\) such that \(\exists S_i\ .\ S_i\,\models \,C_i\), \(A\ |\ \varGamma _l' \vdash _{\cap G}e_2 : T_l''\ |\ C_l'\) such that \(\exists S_l'\ .\ S_l'\,\models \,C_l'\) and \(\ldots \) and \(A\ |\ \varGamma _{l'}' \vdash _{\cap G}e_2 : T_{l'}''\ |\ C_{l'}'\) such that \(\exists S_{l'}'\ .\ S_{l}'\,\models \,C_{l'}'\) then \(A\ |\ \varGamma _i + \varGamma _l' + \ldots + \varGamma _{l'}' \vdash _{\cap G}e_1\ e_2 : T_{i0}\ |\ C_i \cup C_l' \cup \{T_l''\ \dot{\lesssim }\ T_{i1}\} \cup \ldots \cup C_{l'}' \cup \{T_{l'}''\ \dot{\lesssim }\ T_{i{m^i}}\}\).

      Proof for 2.a). By Definition 1, rule 4, we have that \(\varGamma (x) \le (S_i(\varGamma _i) + S_l'(\varGamma _l') + \ldots + S_{l'}'(\varGamma _{l'}'))(x)\). Since substitutions in \(S_i\) and \(S_l'\) and \(\ldots \) and \(S_{l'}'\), don’t affect each other, then \(\varGamma (x) \le S_i \circ S_l' \circ \ldots \circ S_{l'}' (\varGamma _i + \varGamma _l' + \ldots + \varGamma _{l'}')(x)\). For all \(i \in 1..n'\), \(j \in 1 .. m^i\), \(l, l' \in 1 .. k\), for \(A\ |\ \varGamma _i + \varGamma _l' + \ldots + \varGamma _{l'}' \vdash _{\cap G}e_1\ e_2 : T_{i0}\ |\ C_i \cup C_l' \cup \{T_l''\ \dot{\lesssim }\ T_{i1}\} \cup \ldots \cup C_{l'}' \cup \{T_{l'}''\ \dot{\lesssim }\ T_{i{m^i}}\}\) such that \(\exists S_i \circ S_l' \circ S_l'' \circ \ldots \circ S_{l'}' \circ S_{l'}''\ .\ S_i \circ S_l' \circ S_l'' \circ \ldots \circ S_{l'}' \circ S_{l'}''\,\models \,C_i \cup C_l' \cup \{T_l''\ \dot{\lesssim }\ T_{i1}\} \cup \ldots \cup C_{l'}' \cup \{T_{l'}''\ \dot{\lesssim }\ T_{i{m^i}}\}\), with \(S_l''\,\models \,T_l''\ \dot{\lesssim }\ T_{i1}\) and \(\ldots \) and \(S_{l'}''\,\models \,T_{l'}''\ \dot{\lesssim }\ T_{i{m^i}}\), then we have several possibilities. If either \(T_l'' = { Dyn }\) or \(T_{ij} = { Dyn }\), then \([]\,\models \,T_l''\ \dot{\lesssim }\ T_{ij}\), and therefore \(\varGamma (x) \le S_i \circ S_l' \circ S_l'' \circ \ldots \circ S_{l'}' \circ S_{l'}'' (\varGamma _i + \varGamma _l' + \ldots + \varGamma _{l'}')(x)\). If \(T_l'' \in cod(\varGamma _l')\), since \(S_l''\,\models \,T_l''\ \dot{\lesssim }\ T_{ij}\), then \(\varGamma (x) \le S_i \circ S_l' \circ S_l'' \circ \ldots \circ S_{l'}' \circ S_{l'}'' (\varGamma _i + \varGamma _l' + \ldots + \varGamma _{l'}')(x)\). If \(e_1\) is a lambda abstraction, then \(T_{i{m^i}} \not \in cod(\varGamma _i)\). If \(e_1\) is a term variable, then \(T_{ij} \rightarrow T''' \in \varGamma _{i}\), for some \(T'''\). Since \(S_l''\,\models \,T_l''\ \dot{\lesssim }\ T_{ij}\), then \(\varGamma (x) \le S_i \circ S_l' \circ S_l'' \circ \ldots \circ S_{l'}' \circ S_{l'}'' (\varGamma _i + \varGamma _l' + \ldots + \varGamma _{l'}')(x)\).

      Proof for 2.b). If \(S_1(T_{11} \cap \ldots \cap T_{1{m^1}} \rightarrow T_{10}) \cap \ldots \cap S_{n'}(T_{n'1}' \cap \ldots \cap T_{n'm^{n'}} \rightarrow T_{n'0}) \le PM\), then by Definition 1 and \(\rhd \), \(PM = T_1 \cap \ldots \cap T_n \rightarrow T\). Therefore, \(S_1(T_{10}) \cap \ldots \cap S_{n'}(T_{n'0}) \le T\). Since \(T_{i0}\) is not affected by substitutions besides \(S_i\), then \(\textstyle \bigcap _{i = 1}^{n'}(\textstyle \bigcap _{l = 1}^{k} \ldots \textstyle \bigcap _{l' = 1}^{k} S_i \circ S_l' \circ S_l'' \circ \dots \circ S_{l'}' \circ S_{l'}''(T_{i0})) \le T\).

  • Rule T-Gen. If \(\varGamma \vdash _{\cap G}e : T_1 \cap \ldots \cap T_n\) then \(\varGamma \vdash _{\cap G}e : T_1\) and \(\ldots \) and \(\varGamma \vdash _{\cap G}e : T_n\). By the induction hypothesis on 1., exists \(A\ |\ \varGamma _1 \vdash _{\cap G}e : T_1'\ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and \(\ldots \) and exists \(A\ |\ \varGamma _n \vdash _{\cap G}e : T_n'\ |\ C_n\) such that \(\exists S_n\ .\ S_n\,\models \,C_n\).

    By the induction hypothesis on 2., we have that for \(A\ |\ \varGamma _{11} \vdash _{\cap G}e : T_{11}'\ |\ C_{11}\) such that \(\exists S_{11}\ .\ S_{11}\,\models \,C_{11}\) and \(\ldots \) and for \(A\ |\ \varGamma _{1{m^1}} \vdash _{\cap G}e : T_{1{m^1}}'\ |\ C_{1{m^1}}\) such that \(\exists S_{1{m^1}}\ .\ S_{1{m^1}}\,\models \,C_{1{m^1}}\) then for each \(x \in dom(\varGamma ) \cap dom(\textstyle \sum _{j=1}^{m^1} \varGamma _{1j})\), we have that \(\varGamma (x) \le S_{1j}(\varGamma _{1j}(x))\), \(\forall j \in 1 .. {m^1}\), and \(S_{11}(T_{11}') \cap \ldots \cap S_{1{m^1}}(T_{1{m^1}}') \le T_1\) and \(\ldots \) and we have that for \(A\ |\ \varGamma _{n1} \vdash _{\cap G}e : T_{n1}'\ |\ C_{n1}\) such that \(\exists S_{n1}\ .\ S_{n1}\,\models \,C_{n1}\) and \(\ldots \) and for \(A\ |\ \varGamma _{n{m^n}} \vdash _{\cap G}e : T_{n{m^n}}'\ |\ C_{n{m^n}}\) such that \(\exists S_{n{m^n}}\ .\ S_{n{m^n}}\,\models \,C_{n{m^n}}\) then for each \(x \in dom(\varGamma ) \cap dom(\textstyle \sum _{j=1}^{m^n} \varGamma _{nj})\), we have that \(\varGamma (x) \le S_{nj}(\varGamma _{nj}(x))\), \(\forall j \in 1 .. {m^n}\), and \(S_{n1}(T_{n1}') \cap \ldots \cap S_{n{m^n}}(T_{n{m^n}}') \le T_n\).

    Proof for 2.b). By Definition 1, we have that \(S_{11}(T_{11}') \cap \ldots \cap S_{1{m^1}}(T_{1{m^1}}') \cap \ldots \cap S_{n1}(T_{n1}') \cap \ldots \cap S_{n{m^n}}(T_{n{m^n}}') \le T_1 \cap \ldots \cap T_n\).

  • Rule T-Inst. If \(\varGamma _1 \vdash _{\cap G}e : T_i\) then \(\varGamma _1 \vdash _{\cap G}e : T_1 \cap \ldots \cap T_n\). By the induction hypothesis on 1., exists \(A\ |\ \varGamma _2 \vdash _{\cap G}e : T'\ |\ C\) such that \(\exists S\ .\ S\,\models \,C\).

    By the induction hypothesis on 2., we have that for \(A\ |\ \varGamma _{21} \vdash _{\cap G}e : T_1' \ |\ C_1\) such that \(\exists S_1\ .\ S_1\,\models \,C_1\) and \(\ldots \) and for \(A\ |\ \varGamma _{2n} \vdash _{\cap G}e : T_n'\ |\ C_n\) such that \(\exists S_n\ .\ S_n\,\models \,C_n\) then for each \(x \in dom(\varGamma _1) \cap dom(\textstyle \sum _{i=1}^n \varGamma _{2i})\), we have \(\varGamma _1(x) \le S_i(\varGamma _{2i}(x))\), \(\forall i \in 1 .. n\), and \(S_1(T_1') \cap \ldots \cap S_n(T_n') \le T_1 \cap \ldots \cap T_n\).

    Proof for 2.b). As, by Definition 1, \(T_1 \cap \ldots \cap T_n \le T_i\), by transitivity, \(S_1(T_1') \cap \ldots \cap S_n(T_n') \le T_i\).

Lemma 3 (Unification Soundness). If \(C \Rightarrow S\) then \(S\,\models \,C\) .

Proof

We proceed by induction on the length of the derivation tree of \(C \Rightarrow S\).

Base cases:

  • Rule Em. If \(\emptyset \Rightarrow \emptyset \), then by Definition 3, \(\emptyset \,\models \,\emptyset \).

Induction step:

  • Rule CS-DynL. If \(\{{ Dyn }\ \dot{\lesssim }\ T\} \cup C \Rightarrow S\) then \(C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,C\). Since \(S({ Dyn }) \lesssim S(T)\) then \(S\,\models \,{ Dyn }\ \dot{\lesssim }\ T\). Therefore, by Definition 3, \(S\,\models \,\{{ Dyn }\ \dot{\lesssim }\ T\} \cup C\).

  • Rule CS-DynR. If \(\{T\ \dot{\lesssim }\ { Dyn }\} \cup C \Rightarrow S\) then \(C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,C\). Since \(S(T) \lesssim S({ Dyn })\) then \(S\,\models \,T\ \dot{\lesssim }\ { Dyn }\). Therefore, by Definition 3, \(S\,\models \,\{T\ \dot{\lesssim }\ { Dyn }\} \cup C\).

  • Rule CS-Refl. If \(\{T\ \dot{\lesssim }\ T\} \cup C \Rightarrow S\) then \(C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,C\). Since \(S(T) \lesssim S(T)\), then \(S\,\models \,T\ \dot{\lesssim }\ T\). Therefore, by Definition 3, \(S\,\models \,\{T\ \dot{\lesssim }\ T\} \cup C\).

  • Rule CS-Inst. If \(\{T_1 \cap \ldots \cap T_n\ \dot{\lesssim }\ T_1 \cap \ldots \cap T_m\} \cup C \Rightarrow S\) then \(C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,C\). Since \(S(T_1 \cap \ldots \cap T_n) \lesssim S(T_1 \cap \ldots \cap T_m)\), then \(S\,\models \,T_1 \cap \ldots \cap T_n\ \dot{\lesssim }\ T_1 \cap \ldots \cap T_m\). Therefore, by Definition 3, \(S\,\models \,\{T_1 \cap \ldots \cap T_n\ \dot{\lesssim }\ T_1 \cap \ldots \cap T_m\} \cup C\).

  • Rule CS-Assoc. If \(\{(T \rightarrow T_1) \cap \ldots \cap (T \rightarrow T_n)\ \dot{\lesssim }\ T \rightarrow T_1 \cap \ldots \cap T_n\} \cup C \Rightarrow S\) then \(C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,C\). Since \(S((T \rightarrow T_1) \cap \ldots \cap (T \rightarrow T_n)) \lesssim S(T \rightarrow T_1 \cap \ldots \cap T_n)\), then \(S\,\models \,(T \rightarrow T_1) \cap \ldots \cap (T \rightarrow T_n)\ \dot{\lesssim }\ T \rightarrow T_1 \cap \ldots \cap T_n\). Therefore, by Definition 3, \(S\,\models \,\{(T \rightarrow T_1) \cap \ldots \cap (T \rightarrow T_n)\ \dot{\lesssim }\ T \rightarrow T_1 \cap \ldots \cap T_n\} \cup C\).

  • Rule CS-Arrow. If \(\{T_1 \rightarrow T_2\ \dot{\lesssim }\ T_3 \rightarrow T_4\} \cup C \Rightarrow S\) then \(\{T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4\} \cup C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,\{T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4\} \cup C\). Since \(S\,\models \,\{T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4\}\), then \(S(T_3) \lesssim S(T_1)\) and \(S(T_2) \lesssim S(T_4)\). Therefore, by Definition 2, \(S(T_1) \rightarrow S(T_2) \lesssim S(T_3) \rightarrow S(T_4)\). Therefore, \(S(T_1 \rightarrow T_2) \lesssim S(T_3 \rightarrow T_4)\). By Definition 3, \(S\,\models \,\{T_1 \rightarrow T_2\ \dot{\lesssim }\ T_3 \rightarrow T_4\}\). Therefore, by Definition 3, \(S\,\models \,\{T_1 \rightarrow T_2\ \dot{\lesssim }\ T_3 \rightarrow T_4\} \cup C\).

  • Rule CS-InstR. If \(\{T\ \dot{\lesssim }\ T_1 \cap \ldots \cap T_n\} \cup C \Rightarrow S\) then \(\{T\ \dot{\lesssim }\ T_1 \wedge \ldots \wedge T\ \dot{\lesssim }\ T_n\} \cup C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,\{T\ \dot{\lesssim }\ T_1, \ldots , T\ \dot{\lesssim }\ T_n\} \cup C\). Since \(S\,\models \,\{T\ \dot{\lesssim }\ T_1, \ldots , T\ \dot{\lesssim }\ T_n\}\), then by Definition 3, \(S(T) \lesssim S(T_1) \wedge \ldots \wedge S(T) \lesssim S(T_n)\). Therefore, by Definition 2, \(S(T) \lesssim S(T_1) \cap \ldots \cap S(T_n)\). Therefore, \(S(T) \lesssim S(T_1 \cap \ldots \cap T_n)\). By Definition 3, \(S\,\models \,T\ \dot{\lesssim }\ T_1 \cap \ldots \cap T_n\). Therefore, \(S\,\models \,\{T\ \dot{\lesssim }\ T_1 \cap \ldots \cap T_n\} \cup C\).

  • Rule CS-ArrowL. If \(\{T_1 \rightarrow T_2\ \dot{\lesssim }\ T\} \cup C \Rightarrow S\) then \(\{T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4, T = T_3 \rightarrow T_4\} \cup C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,\{T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4, T \doteq T_3 \rightarrow T_4\} \cup C\). Since \(S\,\models \,\{T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4, T \doteq T_3 \rightarrow T_4\}\), then by Definition 3, \(S(T_3) \lesssim S(T_1)\) and \(S(T_2) \lesssim S(T_4)\) and \(S(T) = S(T_3 \rightarrow T_4)\). By Definition of \(\lesssim \), \(S(T_1) \rightarrow S(T_2) \lesssim S(T_3) \rightarrow S(T_4)\). Therefore, \(S(T_1 \rightarrow T_2) \lesssim S(T_3 \rightarrow T_4)\). Since \(S(T) = S(T_3 \rightarrow T_4)\), then \(S(T_1 \rightarrow T_2) \lesssim S(T)\). Therefore, by Definition 3, \(S\,\models \,T_1 \rightarrow T_2\ \dot{\lesssim }\ T\). Therefore, \(S\,\models \,\{T_1 \rightarrow T_2\ \dot{\lesssim }\ T\} \cup C\).

  • Rule CS-ArrowR. If \(\{T\ \dot{\lesssim }\ T_1 \rightarrow T_2\} \cup C \Rightarrow S\) then \(\{T_1\ \dot{\lesssim }\ T_3, T_4\ \dot{\lesssim }\ T_2, T = T_3 \rightarrow T_4\} \cup C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,\{T_1\ \dot{\lesssim }\ T_3, T_4\ \dot{\lesssim }\ T_2, T \doteq T_3 \rightarrow T_4\} \cup C\). Since \(S\,\models \,\{T_1\ \dot{\lesssim }\ T_3, T_4\ \dot{\lesssim }\ T_2, T \doteq T_3 \rightarrow T_4\}\), then by Definition 3, \(S(T_1) \lesssim S(T_3)\) and \(S(T_4) \lesssim S(T_2)\) and \(S(T) = S(T_3 \rightarrow T_4)\). By Definition of \(\lesssim \), \(S(T_3) \rightarrow S(T_4) \lesssim S(T_1) \rightarrow S(T_2)\). Therefore, \(S(T_3 \rightarrow T_4) \lesssim S(T_1 \rightarrow T_2)\). Since \(S(T) = S(T_3 \rightarrow T_4)\), then \(S(T) \lesssim S(T_1 \rightarrow T_2)\). Therefore, by Definition 3, \(S\,\models \,T\ \dot{\lesssim }\ T_1 \rightarrow T_2\). Therefore, \(S\,\models \,\{T\ \dot{\lesssim }\ T_1 \rightarrow T_2\} \cup C\).

  • Rule CS-Eq. If \(\{T_1\ \dot{\lesssim }\ T_2\} \cup C \Rightarrow S\) then \(\{T_1 \doteq T_2\} \cup C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,\{T_1 \doteq T_2\} \cup C\). By Definition 3, \(S(T_1) = S(T_2)\). By Definition 2, \(S(T_1) \lesssim S(T_2)\). By Definition 3, \(S\,\models \,T_1\ \dot{\lesssim }\ T_2\). Therefore, \(S\,\models \,\{T_1\ \dot{\lesssim }\ T_2\} \cup C\).

  • Rule Eq-Refl. If \(\{T \doteq T\} \cup C \Rightarrow S\) then \(C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,C\). Since \(S(T) = S(T)\), then by Definition 3, \(S\,\models \,T \doteq T\). Therefore, \(S\,\models \,\{T \doteq T\} \cup C\).

  • Rule Eq-Arrow. If \(\{T_1 \rightarrow T_2 \doteq T_3 \rightarrow T_4\} \cup C \Rightarrow S\) then \(\{T_1 \doteq T_3, T_2 \doteq T_4\} \cup C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,\{T_1 \doteq T_3, T_2 \doteq T_4\} \cup C\). By Definition 3, \(S(T_1) = S(T_3)\) and \(S(T_2) = S(T_4)\). Then \(S(T_1) \rightarrow S(T_2) = S(T_3) \rightarrow S(T_4)\). Therefore, \(S(T_1 \rightarrow T_2) = S(T_3 \rightarrow T_4)\). By Definition 3, \(S\,\models \,T_1 \rightarrow T_2 \doteq T_3 \rightarrow T_4\). Therefore, \(S\,\models \,\{T_1 \rightarrow T_2 \doteq T_3 \rightarrow T_4\} \cup C\).

  • Rule Eq-VarR. If \(\{T \doteq X\} \cup C \Rightarrow S\) then \(\{X \doteq T\} \wedge C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,\{X \doteq T\} \cup C\). By Definition 3, \(S(X) = S(T)\). Then, \(S(T) = S(X)\). By Definition 3, \(S\,\models \,T \doteq X\). Therefore, \(S\,\models \,\{T \doteq X\} \cup C\).

  • Rule Eq-VarL. If \(\{X \doteq T\} \cup C \Rightarrow S \circ [X \mapsto T]\) then \([X \mapsto T] C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,[X \mapsto T] C\). Then, for each constraint of the form \(T_1' \doteq T_2'\) or \(T_1'\ \dot{\lesssim }\ T_2'\) in C, \(S([X \mapsto T] T_1') = S([X \mapsto T] T_2')\) or \(S([X \mapsto T] T_1') \le S([X \mapsto T] T_2')\). Therefore, \(S \circ [X \mapsto T] (T_1') = S \circ [X \mapsto T] (T_2')\) or \(S \circ [X \mapsto T] (T_1') \le S \circ [X \mapsto T] (T_2')\). Therefore, \(S \circ [X \mapsto T]\,\models \,C\). It follows that \(S \circ [X \mapsto T]\,\models \,\{X \doteq T\} \cup C\), because \(S \circ [X \mapsto T] (X) = S \circ [X \mapsto T] (T)\). Therefore, \(S \circ [X \mapsto T]\,\models \,\{X \doteq T\} \cup C\).

Lemma 4 (Unification Completeness). If \(S_1\,\models \,C\) then \(C \Rightarrow S_2\) for some \(S_2\) , and furthermore \(S_1 = S \circ S_2\) for some S .

Proof

We proceed by induction on the breakdown of constraint sets by the unification rules.

Base cases:

  • Rule Em. If \(S_1\,\models \,\emptyset \) then \(\emptyset \Rightarrow \emptyset \). As \(S_1 = S \circ \emptyset \) for some \(S_1\), it is proved.

Induction step:

  • Rule CS-DynL. If \(S_1\,\models \,\{{ Dyn }\ \dot{\lesssim }\ T\} \cup C\) then by Definition 3, \(S_1\,\models \,C\). By the induction hypothesis, \(C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). As \(C \Rightarrow S_2\), then \(\{{ Dyn }\ \dot{\lesssim }\ T\} \cup C \Rightarrow S_2\).

  • Rule CS-DynR. If \(S_1\,\models \,\{T\ \dot{\lesssim }\ { Dyn }\} \cup C\) then by Definition 3, \(S_1\,\models \,C\). By the induction hypothesis, \(C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). As \(C \Rightarrow S_2\), then \(\{T\ \dot{\lesssim }\ { Dyn }\} \cup C \Rightarrow S_2\).

  • Rule CS-Refl. If \(S_1\,\models \,\{T\ \dot{\lesssim }\ T\} \cup C\) then by Definition 3, \(S_1\,\models \,C\). By the induction hypothesis, \(C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). As \(C \Rightarrow S_2\), then \(\{T\ \dot{\lesssim }\ T\} \cup C \Rightarrow S_2\).

  • Rule CS-Inst. If \(S_1\,\models \,\{T_1 \cap \ldots \cap T_n\ \dot{\lesssim }\ T_1 \cap \ldots \cap T_m\} \cup C\) then by Definition 3, \(S_1\,\models \,C\). By the induction hypothesis, \(C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). As \(C \Rightarrow S_2\), then \(\{T_1 \cap \ldots \cap T_n\ \dot{\lesssim }\ T_1 \cap \ldots \cap T_m\} \cup C \Rightarrow S_2\).

  • Rule CS-Assoc. If \(S_1\,\models \,\{(T \rightarrow T_1) \cap \ldots \cap (T \rightarrow T_n)\ \dot{\lesssim }\ T \rightarrow T_1 \cap \ldots \cap T_n\} \cup C\) then by Definition 3, \(S_1\,\models \,C\). By the induction hypothesis, \(C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). As \(C \Rightarrow S_2\), then \(\{(T \rightarrow T_1) \cap \ldots \cap (T \rightarrow T_n)\ \dot{\lesssim }\ T \rightarrow T_1 \cap \ldots \cap T_n\} \cup C \Rightarrow S_2\).

  • Rule CS-Arrow. If \(S_1\,\models \,\{T_1 \rightarrow T_2\ \dot{\lesssim }\ T_3 \rightarrow T_4\} \cup C\) then by Definition 3, \(S_1(T_1 \rightarrow T_2) \lesssim S_1(T_3 \rightarrow T_4)\) and \(S_1\,\models \,C\). Then, \(S_1(T_1) \rightarrow S_1(T_2) \lesssim S_1(T_3) \rightarrow S_1(T_4)\) and by Definition 2, \(S_1(T_3) \lesssim S_1(T_1)\) and \(S_1(T_2) \lesssim S_1(T_4)\). Then, by Definition 3, \(S_1\,\models \,\{T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4\} \cup C\). By the induction hypothesis, \(\{T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4\} \cup C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). Therefore, \(\{T_1 \rightarrow T_2\ \dot{\lesssim }\ T_3 \rightarrow T_4\} \cup C \Rightarrow S_2\).

  • Rule CS-InstR. If \(S_1\,\models \,\{T\ \dot{\lesssim }\ T_1 \cap \ldots \cap T_n\} \cup C\) then by Definition 3, \(S_1(T) \lesssim S_1(T_1 \cap \ldots \cap T_n)\) and \(S_1\,\models \,C\). Therefore, by Definition 2, \(S_1(T) \lesssim S_1(T_1) \cap \ldots \cap S_1(T_n)\), and therefore, \(S_1(T) \lesssim S_1(T_1)\) and \(\ldots \) and \(S_1(T) \lesssim S_1(T_n)\). By Definition 3, \(S_1\,\models \,\{T\ \dot{\lesssim }\ T_1, \ldots , T\ \dot{\lesssim }\ T_n\} \cup C\). By the induction hypothesis, \(\{T\ \dot{\lesssim }\ T_1, \ldots , T\ \dot{\lesssim }\ T_n\} \cup C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). Therefore, \(\{T\ \dot{\lesssim }\ T_1 \cap \ldots \cap T_n\} \cup C \Rightarrow S_2\).

  • Rule CS-ArrowL. If \(S_1\,\models \,\{T_1 \rightarrow T_2\ \dot{\lesssim }\ T\} \cup C\) then, by Definition 3, \(S_1(T_1 \rightarrow T_2) \lesssim S_1(T)\) and \(S_1\,\models \,C\). Then, it exists a \(T_3\) and \(T_4\), such that \(S_1(T) = S_1(T_3 \rightarrow T_4)\), so that \(S_1(T_1 \rightarrow T_2) \lesssim S_1(T_3 \rightarrow T_4)\). By Definition 2, \(S_1(T_3) \lesssim S_1(T_1)\) and \(S_1(T_2) \lesssim S_1(T_4)\). By Definition 3, \(S_1\,\models \,T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4, T \doteq T_3 \rightarrow T_4 \cup C\). By the induction hypothesis, \(\{T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4, T \doteq T_3 \rightarrow T_4\} \cup C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). Therefore, \(\{T_1 \rightarrow T_2\ \dot{\lesssim }\ T\} \cup C \Rightarrow S_2\).

  • Rule CS-ArrowR. If \(S_1\,\models \,\{T\ \dot{\lesssim }\ T_1 \rightarrow T_2\} \cup C\) then, by Definition 3, \(S_1(T) \lesssim S_1(T_1 \rightarrow T_2)\) and \(S_1\,\models \,C\). Then, it exists a \(T_3\) and \(T_4\), such that \(S_1(T) = S_1(T_3 \rightarrow T_4)\), so that \(S_1(T_1 \rightarrow T_2) \lesssim S_1(T_3 \rightarrow T_4)\). By Definition 2, \(S_1(T_3) \lesssim S_1(T_1)\) and \(S_1(T_2) \lesssim S_1(T_4)\). By Definition 3, \(S_1\,\models \,T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4, T \doteq T_3 \rightarrow T_4 \cup C\). By the induction hypothesis, \(\{T_3\ \dot{\lesssim }\ T_1, T_2\ \dot{\lesssim }\ T_4, T \doteq T_3 \rightarrow T_4\} \cup C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). Therefore, \(\{T_1 \rightarrow T_2\ \dot{\lesssim }\ T\} \cup C \Rightarrow S_2\).

  • Rule CS-Eq. If \(S_1\,\models \,\{T_1\ \dot{\lesssim }\ T_2\} \cup C\) and \(T_1, T_2 \in \{{ Int }, { Bool }\} \cup TVar\) then, by Definition 3, \(S_1(T_1) \lesssim S_1(T_2)\) and \(S_1\,\models \,C\). Therefore, by Definition 2, \(S_1(T_1) = S_1(T_2)\). Then, \(S_1\,\models \,\{T_1 \doteq T_2\}\). By the induction hypothesis, \(\{T_1 \doteq T_2\} \Rightarrow S_2\) and \(S_1 = S \circ S_2\). Therefore, \(\{T_1\ \dot{\lesssim }\ T_2\} \Rightarrow S_2\).

  • Rule Eq-Refl. If \(S_1\,\models \,\{T \doteq T\} \cup C_1\) then, by Definition 3, \(S_1\,\models \,C\). By the induction hypothesis, \(C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). Therefore, \(\{T \doteq T\} \cup C \Rightarrow S_2\).

  • Rule Eq-Arrow. If \(S_1\,\models \,\{T_1 \rightarrow T_2 \doteq T_3 \rightarrow T_4\} \cup C\) then, by Definition 3, \(S_1(T_1 \rightarrow T_2) = S_1(T_3 \rightarrow T_4)\) and \(S_1\,\models \,C\). Then, \(S_1(T_1) \rightarrow S_1(T_2) = S_1(T_3) \rightarrow S_1(T_4)\) and \(S_1(T_1) = S_1(T_3)\) and \(S_1(T_2) = S_1(T_4)\). Then, by Definition 3, \(S_1\,\models \,\{T_1 \doteq T_3, T_2 \doteq T_4\} \cup C\). By the induction hypothesis, \(\{T_1 \doteq T_3, T_2 \doteq T_4\} \cup C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). Therefore, \(\{T_1 \rightarrow T_2 \doteq T_3 \rightarrow T_4\} \cup C \Rightarrow S_2\).

  • Rule Eq-VarR. If \(S_1\,\models \,\{T \doteq X\} \cup C\) then, by Definition 3, \(S_1(T) = S_1(X)\) and \(S_1\,\models \,C\). Then, \(S_1(X) = S_1(T)\) and therefore, \(S_1\,\models \,\{X \doteq T\} \cup C\). By the induction hypothesis, \(\{X \doteq T\} \cup C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). Therefore, \(\{T \doteq X\} \cup C \Rightarrow S_2\).

  • Rule Eq-VarL. If \(S_1\,\models \,\{X \doteq T\} \cup C\) then, by Definition 3, \(S_1(X) = S_1(T)\) and \(S_1\,\models \,C\). Then, \(S_1\,\models \,[X \mapsto T]C\). By the induction hypothesis, \([X \mapsto T]C \Rightarrow S_2\) and \(S_1 = S \circ S_2\). Therefore, \(\{X \doteq T\} \cup C \Rightarrow S_2 \circ [X \mapsto T]\) and \(S_1 = S \circ S_2 \circ [X \mapsto T]\).

Lemma 5 (Unification Soundness). If \(G\ |\ C \Rightarrow S\) then \(S\,\models \,C\) .

Proof

Only proofs for cases Em, CS-DynL, CS-DynR and Eq-VarL are included since proofs for other cases are straightforward adaptations from the proofs of Lemma 3. We proceed by induction on the length of the derivation tree of \(G\ |\ C \Rightarrow S\).

Base cases:

  • Rule Em. If \(G\ |\ \emptyset \Rightarrow \overline{[Vars(G) \mapsto { Dyn }]}\), then by Definition 3, \(\overline{[Vars(G) \mapsto { Dyn }]}\,\models \,\emptyset \).

Induction step:

  • Rule CS-DynL. If \(G\ |\ \{{ Dyn }\ \dot{\lesssim }\ T\} \cup C \Rightarrow S\) then \(G \cup \{T\}\ |\ C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,C\). Since \(S({ Dyn }) \lesssim S(T)\) then \(S\,\models \,{ Dyn }\ \dot{\lesssim }\ T\). Therefore, by Definition 3, \(S\,\models \,\{{ Dyn }\ \dot{\lesssim }\ T\} \cup C\).

  • Rule CS-DynR. If \(G\ |\ \{T\ \dot{\lesssim }\ { Dyn }\} \cup C \Rightarrow S\) then \(G \cup \{T\}\ |\ C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,C\). Since \(S(T) \lesssim S({ Dyn })\) then \(S\,\models \,T\ \dot{\lesssim }\ { Dyn }\). Therefore, by Definition 3, \(S\,\models \,\{T\ \dot{\lesssim }\ { Dyn }\} \cup C\).

  • Rule Eq-VarL. If \(G\ |\ \{X \doteq T\} \cup C \Rightarrow S \circ [X \mapsto T]\) then \([X \mapsto T] G\ |\ [X \mapsto T] C \Rightarrow S\). By the induction hypothesis, \(S\,\models \,[X \mapsto T] C\). Then, for each constraint of the form \(T_1' \doteq T_2'\) or \(T_1'\ \dot{\lesssim }\ T_2'\) in C, \(S([X \mapsto T] T_1') = S([X \mapsto T] T_2')\) or \(S([X \mapsto T] T_1') \le S([X \mapsto T] T_2')\). Therefore, \(S \circ [X \mapsto T] (T_1') = S \circ [X \mapsto T] (T_2')\) or \(S \circ [X \mapsto T] (T_1') \le S \circ [X \mapsto T] (T_2')\). Therefore, \(S \circ [X \mapsto T]\,\models \,C\). It follows that \(S \circ [X \mapsto T]\,\models \,\{X \doteq T\} \cup C\), because \(S \circ [X \mapsto T] (X) = S \circ [X \mapsto T] (T)\). Therefore, \(S \circ [X \mapsto T]\,\models \,\{X \doteq T\} \cup C\).

Lemma 6 (Unification Completeness). If \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]}\,\models \,C\) then \(G\ |\ C \Rightarrow S_2\) for some \(S_2\), and furthermore \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]} = S \circ S_2\) for some S.

Proof

Only proofs for cases Em, CS-DynL, CS-DynR and Eq-VarL are included since proofs for other cases are straightforward adaptations from the proofs of Lemma 4. We proceed by induction on the breakdown of constraint sets by the unification rules.

Base cases:

  • Rule Em. If \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]}\,\models \,\emptyset \) then \(G\ |\ \emptyset \Rightarrow \overline{[Vars(G) \mapsto { Dyn }]}\). As \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]} = S \circ \overline{[Vars(G) \mapsto { Dyn }]}\) for some S, it is proved.

Induction step:

  • Rule CS-DynL. If \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]}\,\models \,\{{ Dyn }\ \dot{\lesssim }\ T\} \cup C\) then by Definition 3, \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]}\,\models \,C\). By the induction hypothesis, \(G \cup \{T\}\ |\ C \Rightarrow S_2\) and \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]} = S \circ S_2\). As \(G \cup \{T\}\ |\ C \Rightarrow S_2\), then \(G\ |\ \{{ Dyn }\ \dot{\lesssim }\ T\} \cup C \Rightarrow S_2\).

  • Rule CS-DynR. If \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]}\,\models \,\{T\ \dot{\lesssim }\ { Dyn }\} \cup C\) then by Definition 3, \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]}\,\models \,C\). By the induction hypothesis, \(G \cup \{T\}\ |\ C \Rightarrow S_2\) and \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]} = S \circ S_2\). As \(G \cup \{T\}\ |\ C \Rightarrow S_2\), then \(G\ |\ \{T\ \dot{\lesssim }\ { Dyn }\} \cup C \Rightarrow S_2\).

  • Rule Eq-VarL. If \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]}\,\models \,\{X \doteq T\} \cup C\) then, by Definition 3, \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]}(X) = S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]}(T)\) and \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]}\,\models \,C\). Then, \(S_1\,\models \,[X \mapsto T]C\). By the induction hypothesis, \([X \mapsto T]G\ |\ [X \mapsto T]C \Rightarrow S_2\) and \(S_1 \circ \overline{[Vars(G) \mapsto { Dyn }]} = S \circ S_2\). Therefore, \(G\ |\ \{X \doteq T\} \cup C \Rightarrow S_2 \circ [X \mapsto T]\).

Theorem 2 (Soundness). If \((\varGamma , T, S) \in I(e)\) then \(S(\varGamma ) \vdash _{\cap G}S(e) : S(T)\) .

Proof

If \((\varGamma , T, S) \in I(e)\) then by Definition 5, \(\emptyset \ |\ \varGamma \vdash _{\cap G}e : T\ |\ C\), \(\emptyset \ |\ C \Rightarrow S\). By Lemma 5, \(S\,\models \,C\). Therefore, by Lemma 1, \(S(\varGamma ) \vdash _{\cap G}S(e) : S(T)\).

Theorem 3 (Principal Typings). If \(\varGamma _1 \vdash _{\cap G}e : T_1\) then there are \(\varGamma _{21}, \ldots , \varGamma _{2n}\) , \(T_{21}, \ldots , T_{2n}\) , \(S_{21}, \ldots , S_{2n}\) and \(S_1, \ldots , S_n\) such that \(((\varGamma _{21}, T_{21}, S_{21}),\ldots ,(\varGamma _{2n}, T_{2n}, S_{2n})) = I(e)\) and, for each \(x \in dom(\varGamma _1) \cap dom(\varGamma _{21} + \ldots + \varGamma _{2n})\) , we have \(\varGamma _1(x) \le S_1 \circ S_{21}(\varGamma _{21}(x))\) and \(\ldots \) and \(\varGamma _1(x) \le S_n \circ S_{2n}(\varGamma _{2n}(x))\) and \(S_1 \circ S_{21}(T_{21}) \cap \ldots \cap S_n \circ S_{2n}(T_{2n}) \le T_1\) .

Proof

If \(\varGamma _1 \vdash _{\cap G}e : T_1\) then by Lemma 2, for \(A\ |\ \varGamma _{21} \vdash _{\cap G}e : T_{21}\ |\ C_1\) such that \(\exists S_{11}\ .\ S_{11}\,\models \,C_1\) and \(\ldots \) and for \(A\ |\ \varGamma _{2n} \vdash _{\cap G}e : T_{2n}\ |\ C_n\) such that \(\exists S_{1n}\ .\ S_{1n}\,\models \,C_n\) then for each \(x \in dom(\varGamma _1) \cap dom(\varGamma _{21} + \ldots + \varGamma _{2n})\), we have \(\varGamma _1(x) \le S_{11}(\varGamma _{21}(y))\) and \(\ldots \) and \(\varGamma _1(x) \le S_{1n}(\varGamma _{2n}(y))\) and \(S_{11}(T_{21}) \cap \ldots \cap S_{1n}(T_{2n}) \le T_1\). By Lemma 6, \(G_1\ |\ C_1 \Rightarrow S_{21}\) for some \(S_{21}\) and furthermore \(S_{11} = S_1 \circ S_{21}\), for some \(S_1\) and \(\ldots \) and \(G_n\ |\ C_n \Rightarrow S_{2n}\) for some \(S_{2n}\) and furthermore \(S_{1n} = S_n \circ S_{2n}\), for some \(S_n\). As \(A\ |\ \varGamma _{21} \vdash _{\cap G}e : T_{21}\ |\ C_1\) and \(G_1\ |\ C_1 \Rightarrow S_{21}\) and \(\ldots \) and \(A\ |\ \varGamma _{2n} \vdash _{\cap G}e : T_{2n}\ |\ C_n\) and \(G_n\ |\ C_n \Rightarrow S_{2n}\), then by Definition 5, \(((\varGamma _{21}, T_{21}, S_{21}), \ldots , (\varGamma _{2n}, T_{2n}, S_{2n})) = I(e)\) and for each \(x \in dom(\varGamma _1) \cap dom(\varGamma _{21} + \ldots + \varGamma _{2n})\), \(\varGamma _1(x) \le S_1 \circ S_{21}(\varGamma _{21}(x))\) and \(\ldots \) and \(\varGamma _1(x) \le S_n \circ S_{2n}(\varGamma _{2n}(x))\) and \(S_1 \circ S_{21}(T_{21}) \cap \ldots \cap S_n \circ S_{2n}(T_{2n}) \le T_1\).

Lemma 8 (Termination of Constraint Solving). \(C \Rightarrow S\) terminates for every set of constraints C .

Proof

A unification problem \(C \Rightarrow S\) is solved if \(C = \emptyset \). We define the following metrics with respect to the unification problem \(C \Rightarrow S\):

  • NICS is the number of unique intersection types in the left of an \(\dot{\lesssim }\) constraint + the number of unique intersection types in the right of an \(\dot{\lesssim }\) constraint

  • NCCS is the number of type constructors in \(\dot{\lesssim }\) constraints

  • NCS is the number of \(\dot{\lesssim }\) constraints

  • NVEq is the number of different type variables in \(\doteq \) constraints

  • NCEq is the number of type constructors in \(\doteq \) constraints

  • NTXEq is the number of \(\doteq \) constraints of the form \(T \doteq X\)

  • NEq is the number of \(\doteq \) constraints

We will prove termination by showing that both NCS and NEq reduce to 0.

The first part of the proof consists of reducing only \(\dot{\lesssim }\) constraints. Termination of \(C \Rightarrow S\), is proved by a measure function that maps the constraint set C to a tuple (NICS, NCCS, NCS). The following table shows that each step decreases the tuple w.r.t. the lexicographic order:

figure a

Note that the number of \(\dot{\lesssim }\) constraints decreases to 0, leaving only \(\doteq \) constraints in C.

The second part of the proof consists of reducing the remaining \(\doteq \) constraints. Termination of \(C \Rightarrow S\), where now only \(\doteq \) are in C, is proved by a measure function that maps the constraint set C to a tuple (NVEq, NCEq, NTXEq, NEq). The following table shows that each step decreases the tuple w.r.t. the lexicographic order:

figure b

Note that the number of \(\doteq \) constraints decreases to 0, leaving C empty.

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Ângelo, P., Florido, M. (2020). Type Inference for Rank 2 Gradual Intersection Types. In: Bowman, W., Garcia, R. (eds) Trends in Functional Programming. TFP 2019. Lecture Notes in Computer Science(), vol 12053. Springer, Cham. https://doi.org/10.1007/978-3-030-47147-7_5

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-47147-7_5

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-47146-0

  • Online ISBN: 978-3-030-47147-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics