Abstract
We extend classic union and intersection type systems with a type-case construction and show that the combination of the union elimination rule of the former and the typing rules for type-cases of our extension encompasses occurrence typing. To apply this system in practice, we define a canonical form for the expressions of our extension, called MSC-form. We show that an expression of the extension is typable if and only if its MSC-form is, and reduce the problem of typing the latter to the one of reconstructing annotations for that term. We provide a sound algorithm that performs this reconstruction and a proof-of-concept implementation.
Supplemental Material
Available for Download
Version including appendixes. Appendixes contain all the definitions and deduction rules omitted in the main text, the extensions with records and let-constructs, and all the proofs of the theorems/properties stated in the main text.
- Franco Barbanera, Mariangiola Dezani-Ciancaglini, and Ugo de’Liguoro. 1995. Intersection and Union Types. Inf. Comput., 119, 2 (1995), June, 202–230. issn:0890-5401 https://doi.org/10.1006/inco.1995.1086 Google Scholar
Digital Library
- Giuseppe Castagna. 2020. Covariance and Controvariance: a fresh look at an old issue (a primer in advanced type systems for learning functional programmers). Logical Methods in Computer Science, 16, 1 (2020), 15:1–15:58. https://doi.org/10.23638/LMCS-16(1:15)2020 Google Scholar
Cross Ref
- Giuseppe Castagna and Victor Lanvin. 2017. Gradual Typing with Union and Intersection Types. Proc. ACM Program. Lang., 1, ICFP (2017), Article 41, Aug., 28 pages. issn:2475-1421 https://doi.org/10.1145/3110285 Google Scholar
Digital Library
- Giuseppe Castagna, Victor Lanvin, Mickaël Laurent, and Kim Nguyễn. 2021. Revisiting Occurrence Typing. oct, arXiv:1907.05590. To appear in Science of Computer Programming, ElsevierGoogle Scholar
- Giuseppe Castagna, Victor Lanvin, Tommaso Petrucciani, and Jeremy G. Siek. 2019. Gradual Typing: a New Perspective. Proc. ACM Program. Lang., 3, POPL ’19 46th ACM Symposium on Principles of Programming Languages (2019), Article 16, Jan., 32 pages. https://doi.org/10.1145/3290329 Google Scholar
Digital Library
- Giuseppe Castagna, Mickaël Laurent, Kim Nguyễn, and Matthew Lutze. 2022. Prototype for Article: On Type-Cases, Union Elimination, and Occurrence Typing. https://doi.org/10.1145/3462306 Online interactive version available at Google Scholar
Digital Library
- Giuseppe Castagna, Kim Nguyễn, Zhiwu Xu, and Pietro Abate. 2015. Polymorphic functions with set-theoretic types. Part 2: local type inference and type reconstruction. In Proceedings of the 42nd Annual ACM SIGPLAN Symposium on Principles of Programming Languages (POPL ’15). 289–302. https://doi.org/10.1145/2676726.2676991 Google Scholar
Digital Library
- Giuseppe Castagna, Kim Nguyễn, Zhiwu Xu, Hyeonseung Im, Sergueï Lenglet, and Luca Padovani. 2014. Polymorphic Functions with Set-Theoretic Types. Part 1: Syntax, Semantics, and Evaluation. In Proceedings of the 41st Annual ACM SIGPLAN Symposium on Principles of Programming Languages (POPL ’14). 5–17. https://doi.org/10.1145/2676726.2676991 Google Scholar
Digital Library
- Giuseppe Castagna, Tommaso Petrucciani, and Kim Nguyễn. 2016. Set-Theoretic Types for Polymorphic Variants. In ICFP ’16, 21st ACM SIGPLAN International Conference on Functional Programming. 378–391. https://doi.org/10.1145/2951913.2951928 Google Scholar
Digital Library
- Giuseppe Castagna and Zhiwu Xu. 2011. Set-theoretic Foundation of Parametric Polymorphism and Subtyping. In ICFP ’11: 16th ACM-SIGPLAN International Conference on Functional Programming. 94–106. https://doi.org/10.1145/2034773.2034788 Google Scholar
Digital Library
- The CDuce Compiler. https://www.cduce.orgGoogle Scholar
- Arthur Charguéraud. 2012. The Locally Nameless Representation. J. Autom. Reason., 49, 3 (2012), 363–408. https://doi.org/10.1007/s10817-011-9225-2 Google Scholar
Cross Ref
- Avik Chaudhuri, Panagiotis Vekris, Sam Goldman, Marshall Roch, and Gabriel Levi. 2017. Fast and Precise Type Checking for JavaScript. Proc. ACM Program. Lang., 1, OOPSLA (2017), Article 48, Oct., 30 pages. issn:2475-1421 https://doi.org/10.1145/3133872 Google Scholar
Digital Library
- Mariangiola Dezani-Ciancaglini. 2020. Personal communicationGoogle Scholar
- Mariangiola Dezani-Ciancaglini, Alain Frisch, Elio Giovannetti, and Yoko Motohama. 2003. The Relevance of Semantic Subtyping. Electronic Notes in Theoretical Computer Science, 70, 1 (2003), 88 – 105. issn:1571-0661 https://doi.org/10.1016/S1571-0661(04)80492-4 ITRS ’02, Intersection Types and Related Systems (FLoC Satellite Event) Google Scholar
Cross Ref
- Jana Dunfield and Neel Krishnaswami. 2019. Bidirectional Typing. CoRR, abs/1908.05839 (2019), arxiv:1908.05839.Google Scholar
- Jana Dunfield and Neelakantan R. Krishnaswami. 2019. Sound and Complete Bidirectional Typechecking for Higher-Rank Polymorphism with Existentials and Indexed Types. Proc. ACM Program. Lang., 3, POPL (2019), Article 9, Jan., 28 pages. https://doi.org/10.1145/3290322 Google Scholar
Digital Library
- Flow. https://flow.org/Google Scholar
- Alain Frisch. 2004. Théorie, conception et réalisation d’un langage de programmation adapté à XML. Ph. D. Dissertation. Université Paris Diderot. http://www.cduce.org/papers/frisch_phd.pdfGoogle Scholar
- Alain Frisch, Giuseppe Castagna, and Véronique Benzaken. 2002. Semantic Subtyping. In LICS ’02, 17th Annual IEEE Symposium on Logic in Computer Science. IEEE Computer Society Press, 137–146. https://doi.org/10.1109/LICS.2002.1029823 Google Scholar
Cross Ref
- Alain Frisch, Giuseppe Castagna, and Véronique Benzaken. 2008. Semantic subtyping: dealing set-theoretically with function, union, intersection, and negation types. Journal of the ACM, 55, 4 (2008), Sept., 19:1–19:64. issn:0004-5411 http://doi.acm.org/10.1145/1391289.1391293 Google Scholar
Digital Library
- J. Roger Hindley and Jonathan P. Seldin. 2008. Lambda-Calculus and Combinators An Introduction. Cambridge University Press. isbn:978-0-521-89885-0Google Scholar
- Andrew M. Kent. 2019. Advanced Logical Type Systems for Untyped Languages. Ph. D. Dissertation. Indiana University. https://pnwamk.github.io/docs/dissertation.pdfGoogle Scholar
- David MacQueen, Gordon Plotkin, and Ravi Sethi. 1986. An ideal model for recursive polymorphic types. Information and Control, 71, 1 (1986), 95–130. issn:0019-9958 https://doi.org/10.1016/S0019-9958(86)80019-5 Google Scholar
Digital Library
- Per Martin-Löf. 1994. Analytic and Synthetic Judgements in Type Theory. Springer Netherlands, Dordrecht. 87–99. isbn:978-94-011-0834-8 https://doi.org/10.1007/978-94-011-0834-8_5 Google Scholar
Cross Ref
- TypeScript. https://www.typescriptlang.org/Google Scholar
- Tommaso Petrucciani. 2019. Polymorphic Set-Theoretic Types for Functional Languages. Ph. D. Dissertation. Joint Ph.D. Thesis, Università di Genova and Université Paris Diderot. https://tel.archives-ouvertes.fr/tel-02119930Google Scholar
- Benjamin C. Pierce and David N. Turner. 2000. Local Type Inference. ACM Trans. Program. Lang. Syst., 22, 1 (2000), Jan., 1–44. issn:0164-0925 https://doi.org/10.1145/345099.345100 Google Scholar
Digital Library
- François Pottier and Yann Régis-Gianas. 2006. Stratified type inference for generalized algebraic data types. In Proceedings of the 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2006, Charleston, South Carolina, USA, January 11-13, 2006, J. Gregory Morrisett and Simon L. Peyton Jones (Eds.). ACM, 232–244. https://doi.org/10.1145/1111037.1111058 Google Scholar
Digital Library
- Aseem Rastogi, Nikhil Swamy, Cédric Fournet, Gavin Bierman, and Panagiotis Vekris. 2015. Safe and Efficient Gradual Typing for TypeScript. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’15). Association for Computing Machinery, New York, NY, USA. 167–180. isbn:9781450333009 https://doi.org/10.1145/2676726.2676971 Google Scholar
Digital Library
- Patrick Maxim Rondon, Ming Kawaguchi, and Ranjit Jhala. 2008. Liquid types. In Proceedings of the ACM SIGPLAN 2008 Conference on Programming Language Design and Implementation, Tucson, AZ, USA, June 7-13, 2008, Rajiv Gupta and Saman P. Amarasinghe (Eds.). ACM, 159–169. https://doi.org/10.1145/1375581.1375602 Google Scholar
Digital Library
- Amr Sabry and Matthias Felleisen. 1992. Reasoning about Programs in Continuation-Passing Style.. In Proceedings of the 1992 ACM Conference on LISP and Functional Programming (LFP ’92). Association for Computing Machinery, 288–298. isbn:0897914813 https://doi.org/10.1145/141471.141563 Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2008. The Design and Implementation of Typed Scheme. In Proceedings of the 35th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’08). ACM, New York, NY, USA. 395–406. isbn:978-1-59593-689-9 https://doi.org/10.1145/1328438.1328486 Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2010. Logical types for untyped languages. In Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming (ICFP ’10). ACM, New York, NY, USA. 117–128. isbn:978-1-60558-794-3 https://doi.org/10.1145/1863543.1863561 Google Scholar
Digital Library
- 2019. What exactly should we call syntax-directed inference rules? Discussion on the Types mailing list. http://lists.seas.upenn.edu/pipermail/types-list/2019/002138.htmlGoogle Scholar
- Wikipedia. 2021. Peter Parker principle. https://en.wikipedia.org/wiki/With_great_power_comes_great_responsibility [Online; accessed 22-October-2021]Google Scholar
- Andrew K. Wright and Matthias Felleisen. 1994. A Syntactic Approach to Type Soundness. Information and Computation, 115, 1 (1994), 38–94. issn:0890-5401 https://doi.org/10.1006/inco.1994.1093 Google Scholar
Digital Library
Index Terms
On type-cases, union elimination, and occurrence typing
Recommendations
Gradual typing: a new perspective
We define a new, more semantic interpretation of gradual types and use it to ``gradualize'' two forms of polymorphism: subtyping polymorphism and implicit parametric polymorphism. In particular, we use the new interpretation to define three gradual type ...
Gradual typing with union and intersection types
We propose a type system for functional languages with gradual types and set-theoretic type connectives and prove its soundness. In particular, we show how to lift the definition of the domain and result type of an application from non-gradual types to ...
Revisiting occurrence typing
AbstractWe revisit occurrence typing, a technique to refine the type of variables occurring in type-cases and, thus, capture some programming patterns used in untyped languages. Although occurrence typing was tied from its inception to set-...





Comments