ML-Like Inference for Classifiers

  • Cristiano Calcagno
  • Eugenio Moggi
  • Walid Taha
Part of the Lecture Notes in Computer Science book series (LNCS, volume 2986)


Environment classifiers were proposed as a new approach to typing multi-stage languages. Safety was established in the simply-typed and let-polymorphic settings. While the motivation for classifiers was the feasibility of inference, this was in fact not established. This paper starts with the observation that inference for the full classifier-based system fails. We then identify a subset of the original system for which inference is possible. This subset, which uses implicit classifiers, retains significant expressivity (e.g. it can embed the calculi of Davies and Pfenning) and eliminates the need for classifier names in terms. Implicit classifiers were implemented in MetaOCaml, and no changes were needed to make an existing test suite acceptable by the new type checker.


Type System Type Inference Code Fragment Principal Type Linear Time Temporal Logic 
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.


  1. 1.
    Abadi, M., Cardelli, L., Pierce, B., Plotkin, G.: Dynamic typing in a statically typed language. ACM Transactions on Programming Languages and Systems 13(2), 237–268 (1991)CrossRefGoogle Scholar
  2. 2.
    Bawden, A.: Quasiquotation in LISP. In: Danvy, O. (ed.) Proceedings of the Workshop on Partial Evaluation and Semantics-Based Program Manipulation, San Antonio, University of Aarhus, Dept. of Computer Science (1999) (invited talk)Google Scholar
  3. 3.
    Calcagno, C., Moggi, E., Sheard, T.: Closed types for a safe imperative MetaML. Journal of Functional Programming (2003) (to appear)Google Scholar
  4. 4.
    Calcagno, C., Taha, W., Huang, L., Leroy, X.: Implementing multi-stage languages using asts, gensym, and reflection. In: Pfenning, F., Smaragdakis, Y. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 57–76. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  5. 5.
    Damas, L., Milner, R.: Principal type schemes for functional languages. In: 9th ACM Symposium on Principles of Programming Languages, August 1982. ACM, New York (1982)Google Scholar
  6. 6.
    Davies, R.: A temporal-logic approach to binding-time analysis. In: The Symposium on Logic in Computer Science (LICS 1996), New Brunswick, pp. 184–195. IEEE Computer Society Press, Los Alamitos (1996)CrossRefGoogle Scholar
  7. 7.
    Davies, R., Pfenning, F.: A modal analysis of staged computation. In: The Symposium on Principles of Programming Languages (POPL 1996), St. Petersburg Beach, pp. 258–270 (1996)Google Scholar
  8. 8.
    Davies, R., Pfenning, F.: A modal analysis of staged computation. Journal of the ACM 48(3), 555–604 (2001)CrossRefMathSciNetGoogle Scholar
  9. 9.
    Engler, D.R., Hsieh, W.C., Frans Kaashoek, M.: C: A language for high-level, efficient, and machine-independent dynaic code generation. In: Proceedings of the ACM Symposium on Principles of Programming Languages (POPL), St. Petersburg Beach, pp. 131–144 (1996)Google Scholar
  10. 10.
    Ganz, S., Sabry, A., Taha, W.: Macros as multi-stage computations: Type-safe, generative, binding macros in MacroML. In: The International Conference on Functional Programming (ICFP 2001), Florence, Italy, September 2001. ACM, New York (2001)Google Scholar
  11. 11.
    Gomard, C.K., Jones, N.D.: A partial evaluator for untyped lambda calculus. Journal of Functional Programming 1(1), 21–69 (1991)zbMATHCrossRefMathSciNetGoogle Scholar
  12. 12.
    Grant, B., Philipose, M., Mock, M., Chambers, C., Eggers, S.J.: An evaluation of staged run-time optimizations in DyC. In: Proceedings of the Conference on Programming Language Design and Implementation, pp. 293–304 (1999)Google Scholar
  13. 13.
    Roger Hindley, J.: Basic Simple Type Theory. Cambridge Tracts in Theoretical Computer Science, vol. 42. Cambridge University Press, Cambridge (1997)zbMATHCrossRefGoogle Scholar
  14. 14.
    Jim, T.: What are principal typings and what are they good for? In: Conf. Rec. POPL 1996: 23rd ACM Symp. Princ. of Prog. Langs. (1996)Google Scholar
  15. 15.
    Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation. Prentice-Hall, Englewood Cliffs (1993)zbMATHGoogle Scholar
  16. 16.
    Kamin, S., Callahan, M., Clausen, L.: Lightweight and generative components II: Binary-level components. In: [27], pp. 28–50 (2000)Google Scholar
  17. 17.
    Launchbury, J., Peyton Jones, S.L.: State in haskell. LISP and Symbolic Computation 8(4), 293–342 (1995)CrossRefGoogle Scholar
  18. 18.
    Launchbury, J., Sabry, A.: Monadic state: Axiomatization and type safety. In: Proceedings of the International Conference on Functional Programming, Amsterdam (1997)Google Scholar
  19. 19.
    MetaOCaml: A compiled, type-safe multi-stage programming language (2001), Available online from:
  20. 20.
    The MetaML Home Page (2000), Provides source code and documentation online at:
  21. 21.
    Nanevski, A., Pfenning, F.: Meta-programming with names and necessity (2003) (submitted)Google Scholar
  22. 22.
    Nielson, F., Nielson, H.R.: Two-level semantics and code generation. Theoretical Computer Science 56(1), 59–133 (1988)zbMATHCrossRefMathSciNetGoogle Scholar
  23. 23.
    Sheard, T., Peyton-Jones, S.: Template meta-programming for haskell. In: Proc. of the workshop on Haskell, pp. 1–16. ACM, New York (2002)CrossRefGoogle Scholar
  24. 24.
    Shields, M., Sheard, T., Peyton Jones, S.L.: Dynamic typing through staged type inference. In: Proceedings of the ACM Symposium on Principles of Programming Languages (POPL), pp. 289–302 (1998)Google Scholar
  25. 25.
    Smith, F., Grossman, D., Morrisett, G., Hornof, L., Jim, T.: Compiling for run-time code generation. Journal of Functional Programming (2003)Google Scholar
  26. 26.
    Taha, W.: Multi-Stage Programming: Its Theory and Applications. PhD thesis, Oregon Graduate Institute of Science and Technology (1999)Google Scholar
  27. 27.
    Taha, W. (ed.): SAIG 2000. LNCS, vol. 1924. Springer, Heidelberg (2000)zbMATHGoogle Scholar
  28. 28.
    Taha, W.: A sound reduction semantics for untyped CBN multi-stage computation. Or, the theory of MetaML is non-trivial. In: Proceedings of the Workshop on Partial Evaluation and Semantics-Based Program Maniplation (PEPM), Boston. ACM Press, New York (2000)Google Scholar
  29. 29.
    Taha, W., Nielsen, M.F.: Environment classifiers. In: The Symposium on Principles of Programming Languages (POPL 2003), New Orleans (2003)Google Scholar
  30. 30.
    Taha, W., Sheard, T.: Multi-stage programming with explicit annotations. In: Proceedings of the Symposium on Partial Evaluation and Semantic-Based Program Manipulation (PEPM), Amsterdam, pp. 203–217. ACM Press, New York (1997)CrossRefGoogle Scholar
  31. 31.
    Wells, J.B.: The essence of principal typings. In: Widmayer, P., Triguero, F., Morales, R., Hennessy, M., Eidenbenz, S., Conejo, R. (eds.) ICALP 2002. LNCS, vol. 2380, pp. 913–925. Springer, Heidelberg (2002)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2004

Authors and Affiliations

  • Cristiano Calcagno
    • 1
  • Eugenio Moggi
    • 2
  • Walid Taha
    • 3
  1. 1.Imperial CollegeLondonUK
  2. 2.DISI, Univ. of GenovaItaly
  3. 3.Rice UniversityUSA

Personalised recommendations