Advertisement

A Rewriting Logic Approach to Type Inference

  • Chucky Ellison
  • Traian Florin Şerbănuţă
  • Grigore Roşu
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5486)

Abstract

Meseguer and Roşu 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.

Keywords

Type System Type Inference Type Environment Type Constraint Type Check 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Meseguer, J., Roşu, G.: Rewriting logic semantics: From language specifications to formal analysis tools. In: Basin, D., Rusinowitch, M. (eds.) IJCAR 2004. LNCS, vol. 3097, pp. 1–44. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  2. 2.
    Meseguer, J., Roşu, G.: The rewriting logic semantics project. J. TCS 373(3), 213–237 (2007)MathSciNetCrossRefzbMATHGoogle Scholar
  3. 3.
    Roşu, G.: K: A rewrite-based framework for modular language design, semantics, analysis and implementation. Technical Report UIUCDCS-R-2006-2802, Computer Science Department, University of Illinois at Urbana-Champaign (2006)Google Scholar
  4. 4.
    Kuan, G., MacQueen, D., Findler, R.B.: A rewriting semantics for type inference. In: De Nicola, R. (ed.) ESOP 2007. LNCS, vol. 4421, pp. 426–440. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  5. 5.
    Felleisen, M., Hieb, R.: A revised report on the syntactic theories of sequential control and state. J. TCS 103(2), 235–271 (1992)MathSciNetCrossRefzbMATHGoogle Scholar
  6. 6.
    Wright, A.K., Felleisen, M.: A syntactic approach to type soundness. Information and Computation 115(1), 38–94 (1994)MathSciNetCrossRefzbMATHGoogle Scholar
  7. 7.
    Matthews, J., Findler, R.B., Flatt, M., Felleisen, M.: A visual environment for developing context-sensitive term rewriting systems. In: van Oostrom, V. (ed.) RTA 2004. LNCS, vol. 3091, pp. 301–311. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  8. 8.
    Milner, R.: A theory of type polymorphism in programming. J. Computer and System Sciences 17(3), 348–375 (1978)MathSciNetCrossRefzbMATHGoogle Scholar
  9. 9.
    Bravenboer, M., Kalleberg, K.T., Vermaas, R., Visser, E.: Stratego/XT Tutorial, Examples, and Reference Manual. Department of Information and Computing Sciences, Universiteit Utrecht (August 2005) (Draft)Google Scholar
  10. 10.
    Barendregt, H.: Introduction to generalized type systems. J. Functional Programming 1(2), 125–154 (1991)MathSciNetzbMATHGoogle Scholar
  11. 11.
    Stehr, M.-O., Meseguer, J.: Pure type systems in rewriting logic: Specifying typed higher-order languages in a first-order logical framework. In: Owe, O., Krogdahl, S., Lyche, T. (eds.) From Object-Orientation to Formal Methods. LNCS, vol. 2635, pp. 334–375. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  12. 12.
    Barendregt, H.P., van Eekelen, M.C.J.D., Glauert, J.R.W., Kennaway, R., Plasmeijer, M.J., Sleep, M.R.: Term graph rewriting. In: de Bakker, J.W., Nijman, A.J., Treleaven, P.C. (eds.) PARLE 1987. LNCS, vol. 259, pp. 141–158. Springer, Heidelberg (1987)CrossRefGoogle Scholar
  13. 13.
    Plump, D.: Term graph rewriting. In: Handbook of Graph Grammars and Computing by Graph Transformation, vol. 2. World Scientific, Singapore (1998)Google Scholar
  14. 14.
    Banach, R.: Simple type inference for term graph rewriting systems. In: Rusinowitch, M., Remy, J.-L. (eds.) CTRS 1992. LNCS, vol. 656, pp. 51–66. Springer, Heidelberg (1993)CrossRefGoogle Scholar
  15. 15.
    Fogarty, S., Pasalic, E., Siek, J., Taha, W.: Concoqtion: Indexed types now! In: PEPM 2007, pp. 112–121. ACM, New York (2007)Google Scholar
  16. 16.
    Kamareddine, F., Klop, J.W.(eds.): Special Issue on Type Theory and Term Rewriting: A Collection of Papers. Journal of Logic and Computation  10(3). Oxford University Press, Oxford (2000)Google Scholar
  17. 17.
    Hünke, Y., de Moor, O.: Aiding dependent type checking with rewrite rules (2001) (unpublished), http://citeseer.ist.psu.edu/huencke01aiding.html
  18. 18.
    Mametjanov, A.: Types and program transformations. In: OOPSLA 2007 Companion, pp. 937–938. ACM, New York (2007)Google Scholar
  19. 19.
    Levin, M.Y., Pierce, B.C.: TinkerType: A language for playing with formal systems. J. Functional Programing 13(2), 295–316 (2003)MathSciNetzbMATHGoogle Scholar
  20. 20.
    Lee, D.K., Crary, K., Harper, R.: Towards a mechanized metatheory of standard ML. In: POPL 2007, pp. 173–184. ACM, New York (2007)Google Scholar
  21. 21.
    Klein, G., Nipkow, T.: A machine-checked model for a Java-like language, virtual machine and compiler. TOPLAS 28(4), 619–695 (2006)CrossRefGoogle Scholar
  22. 22.
    Sewell, P., Nardelli, F.Z., Owens, S., Peskine, G., Ridge, T., Sarkar, S., Strniša, R.: Ott: Effective tool support for the working semanticist. In: ICFP 2007: Proceedings of the 2007 ACM SIGPLAN international conference on Functional programming, pp. 1–12. ACM, New York (2007)CrossRefGoogle Scholar
  23. 23.
    van den Brand, M., et al.: The ASF+SDF meta-environment: A component-based language development environment. In: Wilhelm, R. (ed.) CC 2001. LNCS, vol. 2027, p. 365. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  24. 24.
    Roşu, G.: K: A rewriting-based framework for computations—an informal guide. Technical Report UIUCDCS-R-2007-2926, University of Illinois at Urbana-Champaign (2007)Google Scholar
  25. 25.
    Meseguer, J.: Conditional rewriting logic as a unified model of concurrency. J. TCS 96(1), 73–155 (1992)MathSciNetCrossRefzbMATHGoogle Scholar
  26. 26.
    Clavel, M., Durán, F., Eker, S., Lincoln, P., Martí-Oliet, N., Meseguer, J., Quesada, J.F.: Maude: Specification and programming in rewriting logic. Theor. Comput. Sci. 285(2), 187–243 (2002)MathSciNetCrossRefzbMATHGoogle Scholar
  27. 27.
    Plotkin, G.D.: A structural approach to operational semantics. Journal of Logic and Algebraic Programming 60-61, 17–139 (2004)MathSciNetCrossRefzbMATHGoogle Scholar
  28. 28.
    Gurevich, Y.: Evolving algebras 1993: Lipari guide. In: Specification and validation methods, pp. 9–36. Oxford University Press Inc., New York (1995)Google Scholar
  29. 29.
    Strachey, C., Wadsworth, C.P.: Continuations: A mathematical semantics for handling full jumps. Higher-Order and Symb. Computation 13(1/2), 135–152 (2000)CrossRefzbMATHGoogle Scholar
  30. 30.
    Martelli, A., Montanari, U.: An efficient unification algorithm. ACM Trans. Program. Lang. Syst. 4(2), 258–282 (1982)CrossRefzbMATHGoogle Scholar
  31. 31.
    Roşu, G.: K-style Maude definition of the W type inferencer (2007), http://fsl.cs.uiuc.edu/index.php/Special:WOnline
  32. 32.
    Kothari, S., Caldwell, J.: Algorithm W for lambda calculus extended with Milner-let Implementation used for Type Reconstruction Algorithms—A Survey. Technical Report, University of Wyoming (2007)Google Scholar
  33. 33.
    Li, Z.: Enhtop: A patch for an enhanced OCaml toplevel (2007), http://www.pps.jussieu.fr/~li/software/index.html
  34. 34.
    Eker, S.: Fast matching in combinations of regular equational theories. In: WRLA 1996. ENTCS, vol. 4, pp. 90–109 (1996)Google Scholar
  35. 35.
    Ellison, C.: A rewriting logic approach to defining type systems. Master’s thesis, University of Illinois at Urbana-Champaign (2008), http://fsl.cs.uiuc.edu/pubs/ellison-2008-mastersthesis.pdf
  36. 36.
    Hosabettu, R., Srivas, M.K., Gopalakrishnan, G.: Decomposing the proof of correctness of pipelined microprocessors. In: Y. Vardi, M. (ed.) CAV 1998. LNCS, vol. 1427, pp. 122–134. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  37. 37.
    Kanade, A., Sanyal, A., Khedker, U.P.: A PVS based framework for validating compiler optimizations. In: SEFM 2006, pp. 108–117. IEEE Computer Society, Los Alamitos (2006)Google Scholar
  38. 38.
    Kanade, A., Sanyal, A., Khedker, U.P.: Structuring optimizing transformations and proving them sound. In: COCV 2006. ENTCS, vol. 176(3), pp. 79–95. Elsevier, Amsterdam (2007)Google Scholar
  39. 39.
    Aydemir, B.E., Bohannon, A., Fairbairn, M., Foster, J.N., Pierce, B.C., Sewell, P., Vytiniotis, D., Washburn, G., Weirich, S., Zdancewic, S.: Mechanized metatheory for the masses: The PoplMark challenge. In: Hurd, J., Melham, T. (eds.) TPHOLs 2005. LNCS, vol. 3603, pp. 50–65. Springer, Heidelberg (2005)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2009

Authors and Affiliations

  • Chucky Ellison
    • 1
  • Traian Florin Şerbănuţă
    • 1
  • Grigore Roşu
    • 1
  1. 1.Department of Computer ScienceUniversity of Illinois at Urbana-ChampaignUSA

Personalised recommendations