Abstract
Several type inference approaches for rank-2 idempotent and commutative intersection types have been presented in the literature. Type inference relies on two stages: type constraint generation and solving. Defining constraint generation rules is rather straightforward, with one exception. To infer the type of an application, several derivations of the argument are required, one for each instance of the domain type of the function. The types of these derivations are then constrained against the instances. Noting that these derivations are isomorphic, by renaming of type variables, they can be obtained via a duplication operation on a single derivation of the argument. The application rule then constrains the intersection type resulting from duplication against the domain type of the function, resulting in an equality constraint between intersections. By treating intersections as sets, these constraints can be solved by solving a set unification problem, thus ensuring the types of the argument unify with the domain type of the function. Here we present a new type inference algorithm for rank-2 intersection types, which relies on set unification to solve equality constraints between intersections, and show it is both sound and complete.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
References
Accattoli, B., Graham-Lengrand, S., Kesner, D.: Tight typings and split bounds. In: Proceeding ACM Programming Language, vol. 2(ICFP), pp. 94:1–94:30 (2018)
Alves, S., Kesner, D., Ventura, D.: A quantitative understanding of pattern matching. In: 25th International Conference on Types for Proofs and Programs, TYPES 2019, 11–14 June 2019, Oslo, Norway. LIPIcs, vol. 175, pp. 3:1–3:36. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2019)
Ângelo, P., Florido, M.: Type inference for rank 2 gradual intersection types. In: Bowman, W.J., Garcia, R. (eds.) Trends in Functional Programming, pp. 84–120. Springer International Publishing, Cham (2020). https://doi.org/10.1007/978-3-030-47147-7_5
Ângelo, P., Florido, M.: Type inference for rank-2 intersection types using set unification. Technical report, Faculdade de Ciências & LIACC, Universidade do Porto (2022). https://raw.githubusercontent.com/pedroangelo/papers/master/angelo2022type_complete.pdf
Barendregt, H.P., Dekkers, W., Statman, R.: Lambda Calculus with Types. Perspectives in logic, Cambridge University Press (2013)
Barendregt, H., Coppo, M., Dezani-Ciancaglini, M.: A filter lambda model and the completeness of type assignment. J. Symb. Log. 48(4), 931–940 (1983). https://doi.org/10.2307/2273659
Bettini, L., Bono, V., Dezani-Ciancaglini, M., Giannini, P., Venneri, B.: Java & lambda: a featherweight story. Log. Methods Comput. Sci. 14(3) (2018)
Boudol, G., Zimmer, P.: On type inference in the intersection type discipline. Electron. Notes Theor. Comput. Sci. 136, 23–42 (2005). https://doi.org/10.1016/j.entcs.2005.06.016, https://www.sciencedirect.com/science/article/pii/S1571066105050589. Proceedings of the Third International Workshop on Intersection Types and Related Systems (ITRS 2004)
Bucciarelli, A., Kesner, D., Ventura, D.: Non-idempotent intersection types for the Lambda-Calculus. Logic J. IGPL 25(4), 431–464 (2017). https://doi.org/10.1093/jigpal/jzx018
Carlier, S., Wells, J.B.: Type inference with expansion variables and intersection types in system e and an exact correspondence with \(\beta \)-reduction. In: Proceedings of the 6th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, pp. 132–143. PPDP 2004. Association for Computing Machinery, New York, NY, USA (2004). https://doi.org/10.1145/1013963.1013980
Castagna, G., Lanvin, V.: Gradual typing with union and intersection types. Proc. ACM Program. Lang. 1(ICFP), 1, 41:1–41:28 (2017). https://doi.org/10.1145/3110285
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). https://doi.org/10.1145/3290329
Coppo, M., Dezani-Ciancaglini, M.: An extension of the basic functionality theory for the \(\lambda \)-calculus. Notre Dame J. Formal Logic 21(4), 685–693 (1980). https://doi.org/10.1305/ndjfl/1093883253
Coppo, M., Giannini, P.: Principal types and unification for simple intersection type systems. Inf. Comput. 122(1), 70–96 (1995). https://doi.org/10.1006/inco.1995.1141
Coppo, M.: An extended polymorphic type system for applicative languages. In: Dembiński, P. (ed.) MFCS 1980. LNCS, vol. 88, pp. 194–204. Springer, Heidelberg (1980). https://doi.org/10.1007/BFb0022505
Curry, H.B.: Functionality in combinatory logic. Proc. Nat. Acad. Sci. 20(11), 584–590 (1934). https://doi.org/10.1073/pnas.20.11.584
Damas, L., Milner, R.: Principal type-schemes for functional programs. In: Proceedings of the 9th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 207–212. POPL 1982. ACM, New York, NY, USA (1982). https://doi.org/10.1145/582153.582176
Damiani, F.: Rank 2 intersection types for modules. In: Proceedings of the 5th ACM SIGPLAN International Conference on Principles and Practice of Declaritive Programming, pp. 67–78. PPDP 2003. Association for Computing Machinery, New York, NY, USA (2003). https://doi.org/10.1145/888251.888259
Damiani, F., Giannini, P.: A decidable intersection type system based on relevance. In: Hagiya, M., Mitchell, J.C. (eds.) TACS 1994. LNCS, vol. 789, pp. 707–725. Springer, Heidelberg (1994). https://doi.org/10.1007/3-540-57887-0_122
Dovier, A., Omodeo, E., Pontelli, E., Rossi, G.: A language for programming in logic with finite sets. J. Log. Program. 28, 1–44 (1996)
Dovier, A., Pontelli, E., Rossi, G.: Set unification. Theory Pract. Logic Program. 6(6), 645–701 (2006). https://doi.org/10.1017/S1471068406002730
Dudenhefner, A., Martens, M., Rehof, J.: The algebraic intersection type unification problem. Log. Meth. Comput. Sci. 13 (2017)
Dunfield, J.: Elaborating intersection and union types. In: Proceedings of the 17th ACM SIGPLAN International Conference on Functional Programming, pp. 17–28. ICFP 2012. Association for Computing Machinery, New York, NY, USA (2012). https://doi.org/10.1145/2364527.2364534
Dunfield, J., Pfenning, F.: Type assignment for intersections and unions in call-by-value languages. In: Gordon, A.D. (ed.) FoSSaCS 2003. LNCS, vol. 2620, pp. 250–266. Springer, Heidelberg (2003). https://doi.org/10.1007/3-540-36576-1_16
Florido, M., Damas, L.: Linearization of the lambda-calculus and its relation with intersection type systems. J. Funct. Program. 14(5), 519–546 (2004). https://doi.org/10.1017/S0956796803004970
Frankle, J., Osera, P.M., Walker, D., Zdancewic, S.: Example-directed synthesis: a type-theoretic interpretation. In: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 802–815. POPL 2016. Association for Computing Machinery, New York, NY, USA (2016). https://doi.org/10.1145/2837614.2837629
Freeman, T., Pfenning, F.: Refinement types for ml. In: Proceedings of the ACM SIGPLAN 1991 Conference on Programming Language Design and Implementation, pp. 268–277. PLDI 1991. Association for Computing Machinery, New York, NY, USA (1991). https://doi.org/10.1145/113445.113468
Girard, J.Y.: Une extension de Ĺinterpretation de gödel a Ĺanalyse, et son application a Ĺelimination des coupures dans Ĺanalyse et la theorie des types. In: Fenstad, J. (ed.) Proceedings of the Second Scandinavian Logic Symposium, Studies in Logic and the Foundations of Mathematics, vol. 63, pp. 63–92. Elsevier (1971). https://doi.org/10.1016/S0049-237X(08)70843-7, https://www.sciencedirect.com/science/article/pii/S0049237X08708437
Girard, J.Y., Taylor, P., Lafont, Y.: Proofs and Types. Cambridge University Press, Cambridge (1989)
Henglein, F.: Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst. 15(2), 253–289 (1993). https://doi.org/10.1145/169701.169692
Hindley, J.R.: Basic Simple Type Theory. Cambridge University Press (1997)
Jim, T.: Rank 2 type systems and recursive definitions. Technical report, Cambridge, MA, USA (1995)
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, pp. 42–53. POPL 1996. ACM, New York, NY, USA (1996). https://doi.org/10.1145/237721.237728
Kfoury, A.J., Tiuryn, J., Urzyczyn, P.: Type reconstruction in the presence of polymorphic recursion. ACM Trans. Program. Lang. Syst. 15(2), 290–311 (1993)
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, pp. 161–174. POPL 1999. ACM, New York, NY, USA (1999). https://doi.org/10.1145/292540.292556
Kfoury, A., Wells, J.: Principality and type inference for intersection types using expansion variables. Theoret. Comput. Sci. 311(1), 1–70 (2004). https://doi.org/10.1016/j.tcs.2003.10.032
Leivant, D.: Polymorphic type inference. In: Proceedings of the 10th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, pp. 88–98. POPL 1983. Association for Computing Machinery, New York, NY, USA (1983). https://doi.org/10.1145/567067.567077
Palsberg, J., Pavlopoulou, C.: From polyvariant flow information to intersection and union types. J. Funct. Program. 11(3), 263–317 (2001). https://doi.org/10.1017/S095679680100394X
Pierce, B.C.: Types and Programming Languages. The MIT Press, 1st edn. (2002)
Pottinger, G.: A type assignment for the strongly normalizable lambda-terms. In: Hindley, J., Seldin, J. (eds.) To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, pp. 561–577. Academic Press (1980)
Reynolds, J.C.: Towards a theory of type structure. In: Programming Symposium, Proceedings Colloque Sur La Programmation, pp. 408–423. Springer-Verlag, Berlin, Heidelberg (1974). https://doi.org/10.1007/3-540-06859-7_148
Reynolds, J.C.: Design of the Programming Language Forsythe, pp. 173–233. Birkhäuser Boston, Boston, MA (1997). https://doi.org/10.1007/978-1-4612-4118-8_9
Robinson, J.A.: A machine-oriented logic based on the resolution principle. J. ACM 12(1), 23–41 (1965). https://doi.org/10.1145/321250.321253
Ronchi Della Rocca, S.: Principal type scheme and unification for intersection type discipline. Theor. Comput. Sci. 59(1–2), 181–209 (1988). https://doi.org/10.1016/0304-3975(88)90101-6
Urzyczyn, P.: The emptiness problem for intersection types. In: Proceedings Ninth Annual IEEE Symposium on Logic in Computer Science, pp. 300–309 (1994). https://doi.org/10.1109/LICS.1994.316059
Van Bakel, S.J.: Intersection Type Disciplines in Lambda Calculus and Applicative Term Rewriting Systems. Mathematisch Centrum, Amsterdam (1993)
Wand, M.: A simple algorithm and proof for type inference. Fund. Inform. 10(2), 115–121 (1987)
Acknowledgements
This work was partially financially supported by the portuguese Fundação para a Ciência e a Tecnologia, under the PhD grant number SFRH/BD/145183/2019 and by Base Funding - UIDB/00027/2020 of the Artificial Intelligence and Computer Science Laboratory – LIACC - funded by national funds through the FCT/MCTES (PIDDAC).
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2022 The Author(s), under exclusive license to Springer Nature Switzerland AG
About this paper
Cite this paper
Ângelo, P., Florido, M. (2022). Type Inference for Rank-2 Intersection Types Using Set Unification. In: Seidl, H., Liu, Z., Pasareanu, C.S. (eds) Theoretical Aspects of Computing – ICTAC 2022. ICTAC 2022. Lecture Notes in Computer Science, vol 13572. Springer, Cham. https://doi.org/10.1007/978-3-031-17715-6_29
Download citation
DOI: https://doi.org/10.1007/978-3-031-17715-6_29
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-031-17714-9
Online ISBN: 978-3-031-17715-6
eBook Packages: Computer ScienceComputer Science (R0)