Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Dynamic type inference for gradual Hindley–Milner typing

Published: 02 January 2019 Publication History
  • Get Citation Alerts
  • Abstract

    Garcia and Cimini study a type inference problem for the ITGL, an implicitly and gradually typed language with let-polymorphism, and develop a sound and complete inference algorithm for it. Soundness and completeness mean that, if the algorithm succeeds, the input term can be translated to a well-typed term of an explicitly typed blame calculus by cast insertion and vice versa. However, in general, there are many possible translations depending on how type variables that were left undecided by static type inference are instantiated with concrete static types. Worse, the translated terms may behave differently—some evaluate to values but others raise blame.
    In this paper, we propose and formalize a new blame calculus λBDTI that avoids such divergence as an intermediate language for the ITGL. A main idea is to allow a term to contain type variables (that have not been instantiated during static type inference) and defer instantiation of these type variables to run time. We introduce dynamic type inference (DTI) into the semantics of λBDTI so that type variables are instantiated along reduction. The DTI-based semantics not only avoids the divergence described above but also is sound and complete with respect to the semantics of fully instantiated terms in the following sense: if the evaluation of a term succeeds (i.e., terminates with a value) in the DTI-based semantics, then there is a fully instantiated version of the term that also succeeds in the explicitly typed blame calculus and vice versa.
    Finally, we prove the gradual guarantee, which is an important correctness criterion of a gradually typed language, for the ITGL.

    Supplementary Material

    WEBM File (a18-miyazaki.webm)

    References

    [1]
    Martín Abadi, Luca Cardelli, Benjamin C. Pierce, and Gordon D. Plotkin. 1991. Dynamic Typing in a Statically Typed Language. ACM Transactions on Programming Languages and Systems 13, 2 (1991), 237–268.
    [2]
    Amal Ahmed, Robert Bruce Findler, Jeremy G. Siek, and Philip Wadler. 2011. Blame for all. In Proc. of ACM POPL. 201–214.
    [3]
    Amal Ahmed, Dustin Jamner, Jeremy G. Siek, and Philip Wadler. 2017. Theorems for free for free: parametricity, with and without types. PACMPL 1, ICFP (2017), 39:1–39:28.
    [4]
    Felipe Bañados Schwerter, Ronald Garcia, and Éric Tanter. 2014. A theory of gradual effect systems. In Proc. of ACM ICFP. 283–295.
    [5]
    Felipe Bañados Schwerter, Ronald Garcia, and Éric Tanter. 2016. Gradual type-and-effect systems. Journal of Functional Programming 26 (2016), e19.
    [6]
    Alan Bawden. 1999. Quasiquotation in Lisp. In Proc. of ACM PEPM. 4–12.
    [7]
    Nikolaj Skallerud Bjørner. 1994. Minimal Typing Derivations. In Proceedings of the ACM SIGPLAN Workshop on ML and its Applications. 120–126.
    [8]
    Gilad Bracha and David Griswold. 1993. Strongtalk: Typechecking Smalltalk in a Production Environment. In Proc. of ACM OOPSLA. 215–230.
    [9]
    Val Breazu-Tannen, Thierry Coquand, Carl A. Gunter, and Andre Scedrov. 1991. Inheritance as Implicit Coercion. Inf. Comput. 93, 1 (1991), 172–221.
    [10]
    Robert Cartwright and Mike Fagan. 1991. Soft Typing. In Proc. of ACM PLDI. 278–292.
    [11]
    Matteo Cimini and Jeremy G. Siek. 2016. The Gradualizer: A Methodology and Algorithm for Generating Gradual Type Systems. In Proc. of ACM POPL. 443–455.
    [12]
    Matteo Cimini and Jeremy G. Siek. 2017. Automatically generating the dynamic semantics of gradually typed languages. In Proc. of ACM POPL. 789–803. http://dl.acm.org/citation.cfm?id=3009863
    [13]
    Rowan Davies. 1996. A Temporal-Logic Approach to Binding-Time Analysis. In Proc. of IEEE LICS. 184–195.
    [14]
    Rowan Davies and Frank Pfenning. 2001. A Modal Analysis of Staged Computation. J. ACM 48, 3 (2001), 555–604.
    [15]
    Robert Bruce Findler and Matthias Felleisen. 2002. Contracts for higher-order functions. In Proc. of ACM ICFP. 48–59.
    [16]
    Cormac Flanagan and Matthias Felleisen. 1999. Componential Set-Based Analysis. ACM Transactions on Programming Languages and Systems 21, 2 (1999), 370–416.
    [17]
    Ronald Garcia and Matteo Cimini. 2015. Principal Type Schemes for Gradual Programs. In Proc. of ACM POPL. 303–315.
    [18]
    Ronald Garcia, Alison M. Clark, and Éric Tanter. 2016. Abstracting gradual typing. In Proc. of ACM POPL. 429–442.
    [19]
    Jacques Garrigue. 2004. Relaxing the Value Restriction. In Proc. of FLOPS (LNCS), Vol. 2998. Springer, 196–213.
    [20]
    Jean-Yves Girard. 1972. Interprétation fonctionnelle et élimination des coupures de l’arithmétique d’ordre supérieur. Thèse d’état. Université Paris VII. Summary in Proc. of the Second Scandinavian Logic Symposium, 1971 (63–92).
    [21]
    Robert Harper and John C. Mitchell. 1993. On The Type structure of Standard ML. ACM Transactions on Programming Languages and Systems 15, 2 (1993), 211–252.
    [22]
    Fritz Henglein. 1994. Dynamic Typing: Syntax and Proof Theory. Sci. Comput. Program. 22, 3 (1994), 197–230.
    [23]
    Fritz Henglein and Jakob Rehof. 1995. Safe polymorphic type inference for a Dynamically Typed Language: Translating Scheme to ML. In ACM Conference on Functional Programming and Computer Architecture. 192–203.
    [24]
    David Herman, Aaron Tomb, and Cormac Flanagan. 2007. Space-Efficient Gradual Typing. In Proc. of TFP (Trends in Functional Programming), Vol. 8. Intellect, 1–18.
    [25]
    David Herman, Aaron Tomb, and Cormac Flanagan. 2010. Space-efficient gradual typing. Higher-Order and Symbolic Computation 23, 2 (2010), 167–189.
    [26]
    Yuu Igarashi, Taro Sekiyama, and Atsushi Igarashi. 2017. On polymorphic gradual typing. PACMPL 1, ICFP (2017), 40:1–40:29.
    [27]
    Lintaro Ina and Atsushi Igarashi. 2011. Gradual typing for generics. In Proc. of ACM OOPSLA. 609–624.
    [28]
    Ik-Soon Kim, Kwangkeun Yi, and Cristiano Calcagno. 2006. A polymorphic modal type system for Lisp-like multi-staged languages. In Proc. of ACM POPL. 257–268.
    [29]
    Xavier Leroy. 1993. Polymorphism by Name for References and Continuations. In Conference Record of the Twentieth Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Charleston, South Carolina, USA, January 1993. 220–231.
    [30]
    Robin Milner. 1978. A Theory of Type Polymorphism in Programming. J. Comput. System Sci. 17 (1978), 348–375.
    [31]
    Martin Odersky and Konstantin Läufer. 1996. Putting Type Annotations to Work. In Conference Record of POPL’96: The 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Papers Presented at the Symposium, St. Petersburg Beach, Florida, USA, January 21-24, 1996. 54–67.
    [32]
    Willard Van Orman Quine. 1981. Mathematical Logic (revised edition ed.). Harvard University Press.
    [33]
    Aseem Rastogi, Avik Chaudhuri, and Basil Hosmer. 2012. The ins and outs of gradual type inference. In Proc. of ACM POPL. 481–494.
    [34]
    John Reynolds. 1974. Towards a Theory of Type Structure. In Proc. Colloque sur la Programmation (LNCS), Vol. 19. Springer, 408–425.
    [35]
    John C. Reynolds. 1983. Types, Abstraction and Parametric Polymorphism. In IFIP Congress. 513–523.
    [36]
    Ilya Sergey and Dave Clarke. 2012. Gradual Ownership Types. In Proc. of ESOP (LNCS), Vol. 7211. Springer, 579–599.
    [37]
    Mark Shields, Tim Sheard, and Simon L. Peyton Jones. 1998. Dynamic Typing as Staged Type Inference. In Proc. of ACM POPL. 289–302.
    [38]
    Jeremy G. Siek and Walid Taha. 2006. Gradual typing for functional languages. In Proc. of Workshop on Scheme and Functional Programming. 81–92.
    [39]
    Jeremy G. Siek and Walid Taha. 2007. Gradual Typing for Objects. In Proc. of ECOOP (LNCS), Vol. 4609. Springer, 2–27.
    [40]
    Jeremy G. Siek and Manish Vachharajani. 2008. Gradual typing with unification-based inference. In Proc. of DLS. 7.
    [41]
    Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, and John Tang Boyland. 2015a. Refined Criteria for Gradual Typing. In 1st Summit on Advances in Programming Languages, SNAPL (LIPIcs), Vol. 32. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 274–293.
    [42]
    Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, Sam Tobin-Hochstadt, and Ronald Garcia. 2015b. Monotonic References for Efficient Gradual Typing. In Proc. of ESOP (LNCS), Vol. 9032. Springer, 432–456.
    [43]
    Jeremy G. Siek and Philip Wadler. 2010. Threesomes, with and without blame. In Proc. of ACM POPL. 365–376.
    [44]
    Guy L. Steele, Jr. 1990. Common LISP: the language, 2nd Edition. Digital Pr. http://www.worldcat.org/oclc/20631879
    [45]
    Walid Taha and Michael Florentin Nielsen. 2003. Environment classifiers. In Proc. of ACM POPL. 26–37.
    [46]
    Walid Taha and Tim Sheard. 2000. MetaML and multi-stage programming with explicit annotations. Theoretical Computer Science 248, 1-2 (2000), 211–242.
    [47]
    Satish R. Thatte. 1990. Quasi-Static Typing. In Proc. of ACM POPL. 367–381.
    [48]
    Sam Tobin-Hochstadt and Matthias Felleisen. 2008. The design and implementation of typed Scheme. In Proc. of ACM POPL. 395–406.
    [49]
    Takeshi Tsukada and Atsushi Igarashi. 2010. A Logical Foundation for Environment Classifiers. Logical Methods in Computer Science 6, 4:8 (2010), 1–43.
    [50]
    Philip Wadler and Robert Bruce Findler. 2009. Well-Typed Programs Can’t Be Blamed. In Proc. of ESOP (LNCS), Vol. 5502. Springer, 1–16.
    [51]
    Andrew K. Wright. 1995. Simple Imperative Polymorphism. Lisp and Symbolic Computation 8, 4 (1995), 343–355.
    [52]
    Andrew K. Wright and Matthias Felleisen. 1994. A Syntactic Approach to Type Soundness. Information and Computation 115, 1 (1994), 38–94.
    [53]
    Ningning Xie, Xuan Bi, and Bruno C. d. S. Oliveira. 2018. Consistent Subtyping for All. In Programming Languages and Systems - 27th European Symposium on Programming, ESOP 2018, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2018, Thessaloniki, Greece, April 14-20, 2018, Proceedings. 3–30.

    Cited By

    View all
    • (2024)Space-Efficient Polymorphic Gradual Typing, Mostly ParametricProceedings of the ACM on Programming Languages10.1145/36564418:PLDI(1585-1608)Online publication date: 20-Jun-2024
    • (2024)Generating Python Type Annotations from Type Inference: How Far Are We?ACM Transactions on Software Engineering and Methodology10.1145/365215333:5(1-38)Online publication date: 3-Jun-2024
    • (2024)Type-Based Gradual Typing Performance OptimizationProceedings of the ACM on Programming Languages10.1145/36329318:POPL(2667-2699)Online publication date: 5-Jan-2024
    • Show More Cited By

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image Proceedings of the ACM on Programming Languages
    Proceedings of the ACM on Programming Languages  Volume 3, Issue POPL
    January 2019
    2275 pages
    EISSN:2475-1421
    DOI:10.1145/3302515
    Issue’s Table of Contents
    This work is licensed under a Creative Commons Attribution International 4.0 License.

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 02 January 2019
    Published in PACMPL Volume 3, Issue POPL

    Permissions

    Request permissions for this article.

    Check for updates

    Badges

    Author Tags

    1. dynamic type inference
    2. gradual guarantee
    3. gradual typing

    Qualifiers

    • Research-article

    Funding Sources

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)156
    • Downloads (Last 6 weeks)14
    Reflects downloads up to 11 Aug 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2024)Space-Efficient Polymorphic Gradual Typing, Mostly ParametricProceedings of the ACM on Programming Languages10.1145/36564418:PLDI(1585-1608)Online publication date: 20-Jun-2024
    • (2024)Generating Python Type Annotations from Type Inference: How Far Are We?ACM Transactions on Software Engineering and Methodology10.1145/365215333:5(1-38)Online publication date: 3-Jun-2024
    • (2024)Type-Based Gradual Typing Performance OptimizationProceedings of the ACM on Programming Languages10.1145/36329318:POPL(2667-2699)Online publication date: 5-Jan-2024
    • (2024)Gradual Typing Performance, Micro Configurations and Macro PerspectivesTheoretical Aspects of Software Engineering10.1007/978-3-031-64626-3_15(261-278)Online publication date: 29-Jul-2024
    • (2023)How Profilers Can Help Navigate Type MigrationProceedings of the ACM on Programming Languages10.1145/36228177:OOPSLA2(544-573)Online publication date: 16-Oct-2023
    • (2023)How to Evaluate Blame for Gradual Types, Part 2Proceedings of the ACM on Programming Languages10.1145/36078367:ICFP(159-186)Online publication date: 30-Aug-2023
    • (2022)Static inference meets deep learningProceedings of the 44th International Conference on Software Engineering10.1145/3510003.3510038(2019-2030)Online publication date: 21-May-2022
    • (2022)Migrating gradual typesJournal of Functional Programming10.1017/S095679682200008932Online publication date: 6-Oct-2022
    • (2021)Putting Gradual Types to WorkPractical Aspects of Declarative Languages10.1007/978-3-030-67438-0_4(54-70)Online publication date: 18-Jan-2021

    View Options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Get Access

    Login options

    Full Access

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media