Typed Tagless Final Interpreters

  • Oleg Kiselyov
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7470)


The so-called ‘typed tagless final’ approach of [6] has collected and polished a number of techniques for representing typed higher-order languages in a typed metalanguage, along with type-preserving interpretation, compilation and partial evaluation. The approach is an alternative to the traditional, or ‘initial’ encoding of an object language as a (generalized) algebraic data type. Both approaches permit multiple interpretations of an expression, to evaluate it, pretty-print, etc. The final encoding represents all and only typed object terms without resorting to generalized algebraic data types, dependent or other fancy types. The final encoding lets us add new language forms and interpretations without breaking the existing terms and interpreters.

These lecture notes introduce the final approach slowly and in detail, highlighting extensibility, the solution to the expression problem, and the seemingly impossible pattern-matching. We develop the approach further, to type-safe cast, run-time-type representation, Dynamics, and type reconstruction. We finish with telling examples of type-directed partial evaluation and encodings of type-and-effect systems and linear lambda-calculus.


Denotational Semantic Type Checker Object Term Expression Problem Sample Term 
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.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Asai, K.: On typing delimited continuations: Three new solutions to the printf problem. Higher-Order and Symbolic Computation 22(3), 275–291 (2009)MathSciNetzbMATHCrossRefGoogle Scholar
  2. 2.
    Atkey, R.: Syntax for Free: Representing Syntax with Binding Using Parametricity. In: Curien, P.-L. (ed.) TLCA 2009. LNCS, vol. 5608, pp. 35–49. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  3. 3.
    Atkey, R., Lindley, S., Yallop, J.: Unembedding domain-specific languages. In: Weirich, S. (ed.) Proceedings of the 2nd ACM SIGPLAN Symposium on Haskell, pp. 37–48. ACM Press, New York (2009)CrossRefGoogle Scholar
  4. 4.
    Baars, A.I., Swierstra, S.D.: Typing dynamic typing. In: [21], pp. 157–166 (2002)Google Scholar
  5. 5.
    Böhm, C., Berarducci, A.: Automatic synthesis of typed Λ-programs on term algebras. Theoretical Computer Science 39, 135–154 (1985)MathSciNetzbMATHCrossRefGoogle Scholar
  6. 6.
    Carette, J., Kiselyov, O., Shan, C.-c.: Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming 19(5), 509–543 (2009)MathSciNetzbMATHCrossRefGoogle Scholar
  7. 7.
    Church, A.: A formulation of the simple theory of types. Journal of Symbolic Logic 5(2), 56–68 (1940)MathSciNetzbMATHCrossRefGoogle Scholar
  8. 8.
    Danvy, O.: Functional unparsing. Journal of Functional Programming 8(6), 621–625 (1998)zbMATHCrossRefGoogle Scholar
  9. 9.
    Danvy, O.: Lecture notes on type-directed partial evaluation (1999),
  10. 10.
    Danvy, O., Filinski, A.: Representing control: A study of the CPS transformation. Mathematical Structures in Computer Science 2(4), 361–391 (1992)MathSciNetzbMATHCrossRefGoogle Scholar
  11. 11.
  12. 12.
    Fischer, S., Kiselyov, O., Shan, C.-c.: Purely functional lazy non-deterministic programming. In: Hutton, G., Tolmach, A.P. (eds.) ICFP 2009: Proceedings of the ACM International Conference on Functional Programming, pp. 11–22. ACM Press, New York (2009)CrossRefGoogle Scholar
  13. 13.
    Garrigue, J.: Code reuse through polymorphic variants. In: Workshop on Foundations of Software Engineering (2000)Google Scholar
  14. 14.
    Gries, D. (ed.): Programming methodology: A collection of articles by members of IFIP WG 2.3. Springer, Berlin (1978)Google Scholar
  15. 15.
    Guillemette, L.-J., Monnier, S.: A typepreserving compiler in Haskell. In: Hook, J., Thiemann, P. (eds.) ICFP 2008: Proceedings of the ACM International Conference on Functional Programming. ACM SIGPLAN Notices, vol. 43(9), pp. 75–86. ACM Press, New York (2008)CrossRefGoogle Scholar
  16. 16.
    Gunter, C.A., Mitchell, J.C.: Theoretical aspects of object-oriented programming: Types, semantics, and language design. MIT Press, Cambridge (1994)zbMATHGoogle Scholar
  17. 17.
    Hall, C.V., Hammond, K., Peyton-Jones, S.L., Wadler, P.L.: Type classes in Haskell. ACM Transactions on Programming Languages and Systems 18(2), 109–138 (1996)CrossRefGoogle Scholar
  18. 18.
    Hinze, R.: Formatting: A class act. Journal of Functional Programming 13(5), 935–944 (2003)zbMATHCrossRefGoogle Scholar
  19. 19.
    Hofer, C., Ostermann, K., Rendel, T., Moors, A.: Polymorphic embedding of DSLs. In: Smaragdakis, Y., Siek, J.G. (eds.) Proceedings of GPCE 2008: 7th International Conference on Generative Programming and Component Engineering, pp. 137–147. ACM Press, New York (2008)CrossRefGoogle Scholar
  20. 20.
    Hudak, P.: Building domain-specific embedded languages. ACM Computing Surveys 28(4es), 196 (1996)Google Scholar
  21. 21.
    ICFP, ICFP 2002: Proceedings of the ACM International Conference on Functional Programming. ACM Press, New York (2002)Google Scholar
  22. 22.
    Johann, P., Ghani, N.: Foundations for structured programming with GADTs. In: Necula, G.C., Wadler, P. (eds.) POPL 2008: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 297–308. ACM Press, New York (2008)CrossRefGoogle Scholar
  23. 23.
    Kamin, S.: Final data types and their specification. ACM Transactions on Programming Languages and Systems 5(1), 97–121 (1983)zbMATHCrossRefGoogle Scholar
  24. 24.
    Lämmel, R., Kiselyov, O.: Exploring typed language design in Haskell: Lecture 1. Haskell’s take on the Expression Problem (2010),
  25. 25.
    Lämmel, R., Kiselyov, O.: Lecture 2: Spin-offs from the Expression Problem (2010),
  26. 26.
    Magi, S.: Mobile code in C# via finally tagless interpreters (2009),
  27. 27.
    McAdam, B.J.: Y in practical programs. In: Workshop on Fixed Points in Computer Science (2001),
  28. 28.
    Miller, D., Nadathur, G.: A logic programming approach to manipulating formulas and programs. In: Haridi, S. (ed.) IEEE Symposium on Logic Programming, pp. 379–388. IEEE Computer Society Press, Washington, DC (1987)Google Scholar
  29. 29.
    Mu, S.-C.: Typed λ-Calculus Interpreter in Agda (2008),
  30. 30.
    Oliveira, B.C.d.S., Gibbons, J.: TypeCase: A design pattern for type-indexed functions. In: Proceedings of the 2005 Haskell Workshop, pp. 98–109. ACM Press, New York (2005)CrossRefGoogle Scholar
  31. 31.
    Pašalić, E., Taha, W., Sheard, T.: Tagless staged interpreters for typed languages. In: [21], pp. 157–166 (2002)Google Scholar
  32. 32.
    Pfenning, F., Elliott, C.: Higher-order abstract syntax. In: PLDI 1988: Proceedings of the ACM Conference on Programming Language Design and Implementation. ACM SIGPLAN Notices, vol. 23(7), pp. 199–208. ACM Press, New York (1988)CrossRefGoogle Scholar
  33. 33.
    Plotkin, G.D.: LCF considered as a programming language. Theoretical Computer Science 5, 223–255 (1977)MathSciNetCrossRefGoogle Scholar
  34. 34.
    Pogodalla, S.: Abstract Categorial Grammar homepage,
  35. 35.
    Reynolds, J.C.: User-defined types and procedural data structures as complementary approaches to data abstraction. In: Schuman, S.A. (ed.) New Directions in Algorithmic Languages. IFIP Working Group 2.1 on Algol, Rocquencourt, pp. 157–168. INRIA, France (1975); Also in [14, 309–317], [16, 13–23]Google Scholar
  36. 36.
    Swierstra, W.: Data types á la carte. Journal of Functional Programming 18(4), 423–436 (2008)MathSciNetzbMATHCrossRefGoogle Scholar
  37. 37.
    Szabó, Z.G.: Compositionality. In: Zalta, E.N. (ed.) The Stanford Encyclopedia of Philosophy (Winter 2008)Google Scholar
  38. 38.
    Thiemann, P.: Combinators for program generation. Journal of Functional Programming 9(5), 483–525 (1999)MathSciNetzbMATHCrossRefGoogle Scholar
  39. 39.
    Thiemann, P., Sulzmann, M.: Tag-Free Combinators for Binding-Time Polymorphic Program Generation. In: Blume, M., Kobayashi, N., Vidal, G. (eds.) FLOPS 2010. LNCS, vol. 6009, pp. 87–102. Springer, Heidelberg (2010)CrossRefGoogle Scholar
  40. 40.
    Wadler, P.: The expression problem. Message to java-genericity electronic mailing list (1998),
  41. 41.
    Wand, M.: Final algebra semantics and data type extensions. Journal of Computer and System Sciences 19(1), 27–44 (1979)MathSciNetzbMATHCrossRefGoogle Scholar
  42. 42.
    Washburn, G.A., Weirich, S.: Boxes go bananas: Encoding higher-order abstract syntax with parametric polymorphism. Journal of Functional Programming 18(1), 87–140 (2008)MathSciNetzbMATHCrossRefGoogle Scholar
  43. 43.
    Weirich, S.: Encoding Intensional Type Analysis. In: Sands, D. (ed.) ESOP 2001. LNCS, vol. 2028, pp. 92–106. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  44. 44.
    Weirich, S.: Typechecking into GADT (2004),
  45. 45.
    Weirich, S.: Type-safe run-time polytypic programming. Journal of Functional Programming 16(6), 751–791 (2006)MathSciNetCrossRefGoogle Scholar
  46. 46.
    Winskel, G.: Formal semantics of programming languages. MIT Press, Cambridge (1993)zbMATHGoogle Scholar
  47. 47.
    Xi, H., Chen, C., Chen, G.: Guarded recursive datatype constructors. In: POPL 2003: Conference Record of the Annual ACM Symposium on Principles of Programming Languages, pp. 224–235. ACM Press, New York (2003)Google Scholar
  48. 48.
    Xi, H., Pfenning, F.: Eliminating array bound checking through dependent types. In: PLDI 1998: Proceedings of the ACM Conference on Programming Language Design and Implementation. ACM SIGPLAN Notices, vol. 33(5), pp. 249–257. ACM Press, New York (1998)CrossRefGoogle Scholar
  49. 49.
    Yang, Z.: Encoding types in ML-like languages. In: ICFP 1998: Proceedings of the ACM International Conference on Functional Programming. ACM SIGPLAN Notices, vol. 34(1), pp. 289–300. ACM Press, New York (1998)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Oleg Kiselyov

There are no affiliations available

Personalised recommendations