A Rewriting Logic Approach to Type Inference

Meseguer and Rosu proposed rewriting logic semantics (RLS) as a programing language definitional framework that unifies operational and algebraic denotational semantics. RLS has already been used to define a series of didactic and real languages, but its benefits in connection with defining and reasoning about type systems have not been fully investigated. This paper shows how the same RLS style employed for giving formal definitions of languages can be used to define type systems. The same term-rewriting mechanism used to execute RLS language definitions can now be used to execute type systems, giving type checkers or type inferencers. The proposed approach is exemplified by defining the Hindley-Milner polymorphic type inferencer $\mathcal{W}$ as a rewrite logic theory and using this definition to obtain a type inferencer by executing it in a rewriting logic engine. The inferencer obtained this way compares favorably with other definitions or implementations of $\mathcal{W}$. The performance of the executable definition is within an order of magnitude of that of highly optimized implementations of type inferencers, such as that of OCaml.

[1]  Larry Wos,et al.  What Is Automated Reasoning? , 1987, J. Autom. Reason..

[2]  Benjamin C. Pierce,et al.  TinkerType: a language for playing with formal systems , 2003, Journal of Functional Programming.

[3]  José Meseguer,et al.  Conditioned Rewriting Logic as a United Model of Concurrency , 1992, Theor. Comput. Sci..

[4]  Robert Bruce Findler,et al.  A Rewriting Semantics for Type Inference , 2007, ESOP.

[5]  Mads Tofte,et al.  Type Inference for Polymorphic References , 1990, Inf. Comput..

[6]  José Meseguer,et al.  Pure Type Systems in Rewriting Logic: Specifying Typed Higher-Order Languages in a First-Order Logical Framework , 2004, Essays in Memory of Ole-Johan Dahl.

[7]  Tobias Nipkow,et al.  A machine-checked model for a Java-like language, virtual machine, and compiler , 2006, TOPL.

[8]  Detlef Plump,et al.  Term graph rewriting , 1999 .

[9]  Narciso Martí-Oliet,et al.  Maude: specification and programming in rewriting logic , 2002, Theor. Comput. Sci..

[10]  Richard Banach,et al.  Simple Type Inference for Term Graph Rewriting Systems , 1992, CTRS.

[11]  Ganesh Gopalakrishnan,et al.  Decomposing the Proof of Correctness of pipelined Microprocessors , 1998, CAV.

[12]  Tom Ridge,et al.  Ott: effective tool support for the working semanticist , 2007, ICFP '07.

[13]  Matthias Felleisen,et al.  A Syntactic Approach to Type Soundness , 1994, Inf. Comput..

[14]  Steven Eker Fast matching in combinations of regular equational theories , 1996, WRLA.

[15]  Claude Kirchner,et al.  An overview of ELAN , 1998, WRLA.

[16]  Gordon D. Plotkin,et al.  The origins of structural operational semantics , 2004, J. Log. Algebraic Methods Program..

[17]  Gordon D. Plotkin,et al.  A structural approach to operational semantics , 2004, J. Log. Algebraic Methods Program..

[18]  Hartmut Ehrig,et al.  Handbook of graph grammars and computing by graph transformation: vol. 3: concurrency, parallelism, and distribution , 1999 .

[19]  Xavier Leroy,et al.  Polymorphic type inference and assignment , 1991, POPL '91.

[20]  Tom Lyche,et al.  From Object-Orientation to Formal Methods , 2004, Lecture Notes in Computer Science.

[21]  Chucky Ellison,et al.  A Rewriting Logic Approach to Defining Type Systems , 2008 .

[22]  Alberto Martelli,et al.  An Efficient Unification Algorithm , 1982, TOPL.

[23]  Andrew K. Wright Simple imperative polymorphism , 1995, LISP Symb. Comput..

[24]  Hendrik Pieter Barendregt,et al.  Introduction to generalized type systems , 1991, Journal of Functional Programming.

[25]  Walid Taha,et al.  Concoqtion: indexed types now! , 2007, PEPM '07.

[26]  Brian Campbell,et al.  Amortised Memory Analysis Using the Depth of Data Structures , 2009, ESOP.

[27]  David Aspinall,et al.  Formalising Java's Data Race Free Guarantee , 2007, TPHOLs.

[28]  Yuri Gurevich,et al.  Evolving algebras 1993: Lipari guide , 1995, Specification and validation methods.

[29]  Jan Willem Klop,et al.  Term Rewriting Systems: From Church-Rosser to Knuth-Bendix and Beyond , 1990, ICALP.

[30]  J. Caldwell,et al.  Type Reconstruction Algorithms-A Survey , 2007 .

[31]  Marko C. J. D. van Eekelen,et al.  Term Graph Rewriting , 1987, PARLE.

[32]  Aditya Kanade,et al.  A PVS Based Framework for Validating Compiler Optimizations , 2006, Fourth IEEE International Conference on Software Engineering and Formal Methods (SEFM'06).

[33]  Simon Kaplan,et al.  Conditional Term Rewriting Systems , 1987, Lecture Notes in Computer Science.

[34]  Karl Crary,et al.  Towards a mechanized metatheory of standard ML , 2007, POPL '07.

[35]  A. J. Nijman,et al.  PARLE Parallel Architectures and Languages Europe , 1987, Lecture Notes in Computer Science.

[36]  Arie van Deursen,et al.  The ASF+SDF Meta-environment: A Component-Based Language Development Environment , 2001 .

[37]  Matthias Felleisen,et al.  A Visual Environment for Developing Context-Sensitive Term Rewriting Systems , 2004, RTA.

[38]  Grigore Rosu K: a Rewrite-based Framework for Modular Language Design, Semantics, Analysis and Implementation -Version 1- , 2005 .

[39]  Benjamin C. Pierce,et al.  Mechanized Metatheory for the Masses: The PoplMark Challenge , 2005, TPHOLs.

[40]  Egon Börger Specification and validation methods , 1995 .

[41]  Robin Milner,et al.  A Theory of Type Polymorphism in Programming , 1978, J. Comput. Syst. Sci..

[42]  Robin Milner,et al.  Principal type-schemes for functional programs , 1982, POPL '82.

[43]  Azamatbek Mametjanov Types and program transformations , 2007, OOPSLA '07.

[44]  José Meseguer,et al.  Rewriting Logic Semantics: From Language Specifications to Formal Analysis Tools , 2004, IJCAR.

[45]  Robert Hieb,et al.  The Revised Report on the Syntactic Theories of Sequential Control and State , 1992, Theor. Comput. Sci..

[46]  José Meseguer,et al.  The Rewriting Logic Semantics Project , 2006, Electron. Notes Theor. Comput. Sci..

[47]  Eelco Visser,et al.  Program Transformation with Stratego/XT: Rules, Strategies, Tools, and Systems in Stratego/XT 0.9 , 2003, Domain-Specific Program Generation.

[48]  Christopher Strachey,et al.  Continuations: A Mathematical Semantics for Handling Full Jumps , 2000, High. Order Symb. Comput..

[49]  Aditya Kanade,et al.  Structuring Optimizing Transformations and Proving Them Sound , 2007, COCV@ETAPS.