Skip to main content Accessibility help
×
Home
Hostname: page-component-5d6d958fb5-c6lpx Total loading time: 1.134 Render date: 2022-11-29T14:24:34.828Z Has data issue: true Feature Flags: { "shouldUseShareProductTool": true, "shouldUseHypothesis": true, "isUnsiloEnabled": true, "useRatesEcommerce": false, "displayNetworkTab": true, "displayNetworkMapGraph": false, "useSa": true } hasContentIssue true

Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages

Published online by Cambridge University Press:  15 April 2009

JACQUES CARETTE
Affiliation:
McMaster University (e-mail: carette@mcmaster.ca)
OLEG KISELYOV
Affiliation:
FNMOC (e-mail: oleg@pobox.org)
CHUNG-CHIEH SHAN
Affiliation:
Rutgers University (e-mail: ccshan@rutgers.edu)
Rights & Permissions[Opens in a new window]

Abstract

HTML view is not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

We have built the first family of tagless interpretations for a higher-order typed object language in a typed metalanguage (Haskell or ML) that require no dependent types, generalized algebraic data types, or postprocessing to eliminate tags. The statically type-preserving interpretations include an evaluator, a compiler (or staged evaluator), a partial evaluator, and call-by-name and call-by-value continuation-passing style (CPS) transformers. Our principal technique is to encode de Bruijn or higher-order abstract syntax using combinator functions rather than data constructors. In other words, we represent object terms not in an initial algebra but using the coalgebraic structure of the λ-calculus. Our representation also simulates inductive maps from types to types, which are required for typed partial evaluation and CPS transformations. Our encoding of an object term abstracts uniformly over the family of ways to interpret it, yet statically assures that the interpreters never get stuck. This family of interpreters thus demonstrates again that it is useful to abstract over higher-kinded types.

Type
Articles
Copyright
Copyright © Cambridge University Press 2009

References

Ariola, Zena M., Felleisen, Matthias, Maraist, John, Odersky, Martin & Wadler, Philip (1995) The call-by-need lambda calculus. In POPL 95: Conference Record of the Annual ACM Symposium on Principles of Programming Languages. New York: ACM, pp. 233246.CrossRefGoogle Scholar
Asai, Kenichi (2001) Binding-time analysis for both static and dynamic expressions. New Generation Comput. 20 (1), 2752.CrossRefGoogle Scholar
Baars, Arthur I. & Swierstra, S. Doaitse (2002) Typing dynamic typing. In ICFP 2002; Proceedings of the ACM International Conference on Functional Programming. New York: ACM, pp. 157166.Google Scholar
Balat, Vincent, Di Cosmo, Roberto & Fiore, Marcelo P. (2004) Extensional normalisation and type-directed partial evaluation for typed lambda calculus with sums. In POPL 04: Conference Record of the Annual ACM Symposium on Principles of Programming Languages. New York: ACM, pp. 6476.CrossRefGoogle Scholar
Bawden, Alan (1999). Quasiquotation in Lisp. In Proceedings of the 1999 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, Danvy, Olivier (ed). pp. 412. Note NS-99-1, University of Aarhus: BRICS.Google Scholar
Benton, Nick. P. (2005) Embedded interpreters. J. Func. Prog. 15 (4), 503542.CrossRefGoogle Scholar
Berarducci, Alessandro (1996) Infinite lambda-calculus and non-sensible models. In Logic and Algebra, Ursini, A. & Aglianò, P. (eds), vol. 180. Marcel Dekker, pp. 339378.Google Scholar
Birkedal, Lars & Welinder, Morten (1993) Partial evaluation of Standard ML. Master's Thesis, DIKU, University of Copenhagen, Denmark. DIKU Research Report 93/22.Google Scholar
Bjesse, Per, Claessen, Koen, Sheeran, Mary & Singh, Satnam (1998) Lava: Hardware design in Haskell. In ICFP Proceedings of the ACM International Conference on Functional Programming, vol. 34(1) of ACM SIGPLAN Notices. New York: ACM, 1998: pp. 174184.Google Scholar
Böhm, Corrado & Berarducci, Alessandro (1985) Automatic synthesis of typed Λ-programs on term algebras. Theor. Comp. Sci. 39, 135154.CrossRefGoogle Scholar
Bondorf, Anders & Danvy, Olivier (1991) Automatic autoprojection of recursive equations with global variables and abstract data types. Sci. Comp. Prog. 16 (2), 151195.CrossRefGoogle Scholar
Calcagno, Cristiano, Moggi, Eugenio & Taha, Walid (2004) ML-like inference for classifiers. In Programming Languages and Systems: Proceedings of ESOP 2004, 13th European Symposium on Programming, Schmidt, David A. (ed.). Lecture Notes in Computer Science 2986, Berlin: Springer-Verlag, pp. 7993.CrossRefGoogle Scholar
Carette, Jacques & Kiselyov, Oleg (2005) Multi-stage programming with Functors and Monads: Eliminating abstraction overhead from generic code. In Generative Programming and Component Engineering GPCE, Estonia, Lecture Notes in Computer Science, pp. 256274.CrossRefGoogle Scholar
Carette, Jacques, Kiselyov, Oleg & Shan, Chung-chieh (2007) Finally tagless, partially evaluated. In APLAS, Shao, Zhong (ed.), vol. 4807. Lecture Notes in Computer Science. Springer, pp. 222238.Google Scholar
Chen, Chiyan & Xi, Hongwei (2003) Implementing typeful program transformations. In Proceedings of the 2003 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation. New York: ACM, pp. 2028.CrossRefGoogle Scholar
Consel, Charles (1993) A tour of Schism: A partial evaluation system for higher-order applicative languages. In Proceedings of the 1993 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation. New York: ACM, pp. 145154.CrossRefGoogle Scholar
Danvy, Olivier (1996) Type-directed partial evaluation. In POPL 96: Conference record of the Annual ACM Symposium on Principles of Programming Languages. New York: ACM, pp. 242257.CrossRefGoogle Scholar
Danvy, Olivier (1998) A simple solution to type specialization. In Proceedings of ICALP 98: 25th International Colloquium on Automata, Languages, and Programming, Larsen, Kim Guldstrand, Skyum, Sven & Winskel, Glynn (ed.). Lecture Notes in Computer Science, vol. 1443. Berlin: Springer-Verlag, pp. 908917.Google Scholar
Danvy, Olivier & Filinski, Andrzej (1992) Representing control: A study of the CPS transformation. Math. Struct. Comp. Sci. 2 (4), 361391.CrossRefGoogle Scholar
Danvy, Olivier & López, Pablo E. Martínez (2003) Tagging, encoding, and Jones optimality. In Programming Languages and Systems: Proceedings of ESOP 2003, 12th European Symposium on Programming, Degano, Pierpaolo (ed.). Lecture Notes in Computer Science, vol. 2618, Berlin: Springer-Verlag, pp. 335347.CrossRefGoogle Scholar
Davies, Rowan & Pfenning, Frank (2001) A modal analysis of staged computation. J. ACM 48 (3), 555604.CrossRefGoogle Scholar
Filinski, Andrzej (1994) Representing monads. In POPL ’94: Conference Record of the Annual ACM Symposium on Principles of Programming Languages. New York: ACM, pp. 446457.CrossRefGoogle Scholar
Fiore, Marcelo P. (2002) Semantic analysis of normalisation by evaluation for typed lambda calculus. In Proceedings of the 4th International Conference on Principles and Practice of Declarative Programming. New York: ACM, pp 2637.Google Scholar
Fogarty, Seth, Pasalic, Emir, Siek, Jeremy & Taha, Walid (2007) Concoqtion: Indexed types now! In Proceedings of the 2007 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation. New York: ACM.Google Scholar
Futamura, Yoshihiko (1971) Partial evaluation of computation process–An approach to a compiler-compiler. Sys. Comp. Controls 2 (5), 4550. Reprinted with revisions in Higher-Order Symbol. Comput. 12(4), 381–391.Google Scholar
Gomard, Carsten K. & Jones, Neil D. (1991) A partial evaluator for the untyped lambda calculus. J. Funct. Prog. 1 (1), 2169.CrossRefGoogle Scholar
Guillemette, Louis-Julien & Monnier, Stefan (2006) Statically verified type-preserving code transformations in Haskell. In PLPV 2006: Programming Languages Meets Program Verification. Stump, Aaron and Xi, Hongwei. (eds.) Electronic Notes in Theoretical Computer Science, vol. 174(7). Amsterdam: Elsevier Science, pp. 4053.Google Scholar
Harper, Robert & Morrisett, J. Gregory (1995) Compiling polymorphism using intensional type analysis. In POPL 95: Conference Record of the Annual ACM Symposium on Principles of Programming Languages. New York: ACM, pp. 130141.CrossRefGoogle Scholar
Hindley, J. Roger (1969) The principal type-scheme of an object in combinatory logic. Trans. Am. Math. Soc. 146, 2960.Google Scholar
Hinze, Ralf, Jeuring, Johan & Löh, Andres (2004) Type-indexed data types. Sci. Comp. Prog. 51 (1–2), 117151.CrossRefGoogle Scholar
Hofer, Christian, Ostermann, Klaus, Rendel, Tillmann & Moors, Adriaan (2008) Polymorphic embedding of DSLs. In ACM Conference on Generative Programming and Component Engineering GPCE, Nashville, ACM.Google Scholar
Holst, Carsten Kehler (1988) Language triplets: The AMIX approach. In Partial Evaluation and Mixed Computation. Bjørner, Dines, Ershov, Andrei P. and Jones, Neil D. (eds), Amsterdam: North-Holland, pp. 167186.Google Scholar
Honsell, Furio & Lenisa, Marina (1995) Final semantics for untyped lambda-calculus. In TLCA 95: Proceedings of the 2nd International Conference on Typed Lambda Calculi and Applications, Dezani-Ciancaglini, Mariangiola and Plotkin, Gordon D. (eds), Lecture Notes in Computer Science, vol. 902, Berlin: Springer-Verlag, pp. 249265.CrossRefGoogle Scholar
Honsell, Furio & Lenisa, Marina (1999) Coinductive characterizations of applicative structures. Math. Struct. Comp. Sci. 9 (4), 403435.CrossRefGoogle Scholar
Hudak, Paul (1996) Building domain-specific embedded languages. ACM Comput. Surv. 28 (4es), 196.CrossRefGoogle Scholar
Hughes, John (1998) Type specialization. ACM Comput. Surv. 30 (3es:14), 16.CrossRefGoogle Scholar
Jacobs, Bart (2007) Introduction to coalgebra: Towards mathematics of states and observations. http://www.cs.ru.nl/B.Jacobs/CLG/JacobsCoalgebraIntro.pdf. Draft book.Google Scholar
Jones, Neil D., Gomard, Carsten K. & Sestoft, Peter (1993) Partial Evaluation and Automatic Program Generation. Englewood Cliffs, NJ: Prentice-Hall.Google Scholar
Jones, Neil D. & Nielson, Flemming (1994) Abstract interpretation: A semantics-based tool for program analysis. In Handbook of Logic in Computer Science. Oxford University Press, pp. 527629.Google Scholar
Jones, Neil D., Sestoft, Peter & Søndergaard, Harald (1989) Mix: A self-applicable partial evaluator for experiments in compiler generation. Lisp Symbol. Comput. 2 (1), 950.CrossRefGoogle Scholar
Landin, Peter J. (1966) The next 700 programming languages. Commun. ACM 9 (3), 157166.CrossRefGoogle Scholar
Läufer, Konstantin & Odersky, Martin (1993) Self-interpretation and reflection in a statically typed language. In Proceedings of the 4th Annual OOPSLA/ECOOP Workshop on Object-Oriented Reflection and Metalevel Architectures, Washington, ACM.Google Scholar
Makholm, Henning (2000) On Jones-optimal specialization for strongly typed languages. In Semantics, Applications and Implementation of Program Generation, Taha, Walid (ed). Lecture Notes in Computer Science, vol. 1924 Montreal, Canada: Springer-Verlag, pp. 129148.CrossRefGoogle Scholar
Miller, Dale & Nadathur, Gopalan (1987) A logic programming approach to manipulating formulas and programs. In IEEE Symposium on Logic Programming, Haridi, Seif (ed). Washington, DC: IEEE Comp. Society Press, pp. 379388.Google Scholar
Milner, Robin (1978) A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17, 348375.CrossRefGoogle Scholar
Mogensen, Torben Æ. (1992) Efficient self-interpretation in lambda calculus. J. Funct. Prog. 2 (3), 345363.CrossRefGoogle Scholar
Mogensen, Torben Æ. (1995) Self-applicable online partial evaluation of the pure lambda calculus. In Proceedings of the 1995 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program manipulation. New York: ACM Press, pp. 3944.CrossRefGoogle Scholar
Moggi, Eugenio (1991) Notions of computation and monads. Info. Comput. 93 (1), 5592.CrossRefGoogle Scholar
Moors, Adriaan, Piessens, Frank & Odersky, Martin (2008) Generics of a higher kind. In OOPSLA ’08: Proceedings of the 23rd ACM Sigplan Conference on Object Oriented Programming Systems Languages and Applications. New York, NY, ACM, pp. 423438.CrossRefGoogle Scholar
Nanevski, Aleksandar (2002) Meta-programming with names and necessity. In ICFP 2002. Proceedings of the ACM International Conference on Functional Programming. New York: ACM, pp. 206217.Google Scholar
Nanevski, Aleksandar & Pfenning, Frank (2005) Staged computation with names and necessity. J. Funct. Prog. 15 (6), 893939.CrossRefGoogle Scholar
Nanevski, Aleksandar, Pfenning, Frank & Pientka, Brigitte (to appear). Contextual modal type theory. Trans. Comput. Logic 9 (3), 149.Google Scholar
Nielson, Flemming (1988) Strictness analysis and denotational abstract interpretation. Info. Comput. 76 (1), 2992.CrossRefGoogle Scholar
Nielson, Flemming & Nielson, Hanne Riis (1988) Automatic binding time analysis for a typed Λ-calculus. In POPL 88: Conference Record of the Annual ACM Symposium on Principles of Programming Languages. New York: ACM, pp. 98106.CrossRefGoogle Scholar
Nielson, Flemming & Nielson, Hanne Riis (1992) Two-Level Functional Languages. Cambridge University Press.CrossRefGoogle Scholar
Oliveira, Bruno César dos Santos & Gibbons, Jeremy (2005) TypeCase: A design pattern for type-indexed functions. In Proceedings of the 2005 Haskell Workshop. New York: ACM, pp. 98109.CrossRefGoogle Scholar
Pašalić, Emir, Taha, Walid & Sheard, Tim (2002) Tagless staged interpreters for typed languages. In ICFP 2002. Proceedings of the ACM International Conference on Functional Programming. New York: ACM, pp. 157166.Google Scholar
Peyton Jones, Simon L., Vytiniotis, Dimitrios, Weirich, Stephanie & Washburn, Geoffrey (2006) Simple unification-based type inference for GADTs. In ICFP ’06: Proceedings of the ACM International Conference on Functional Programming, New York: ACM, pp. 5061.CrossRefGoogle Scholar
Pfenning, Frank & Elliott, Conal (1988) Higher-order abstract syntax. In PLDI 88: Proceedings of the ACM Conference on Programming Language Design and Implementation. ACM SIGPLAN Notices, vol. 23(7). New York: ACM, pp. 199208.CrossRefGoogle Scholar
Pfenning, Frank & Lee, Peter (1991) Metacircularity in the polymorphic λ-calculus. Theor. Comp. Sci. 89 (1), 137159.CrossRefGoogle Scholar
Plotkin, Gordon D. (1975) Call-by-name, call-by-value and the λ-calculus. Theor. Comp. Sci. 1 (2), 125159.CrossRefGoogle Scholar
Plotkin, Gordon D. (1977) LCF considered as a programming language. Theor. Comp. Sci. 5, 223255.CrossRefGoogle Scholar
Ramsey, Norman (2005) ML module mania: A type-safe, separately compiled, extensible interpreter. In Proceedings of the 2005 Workshop on ML. Electronic Notes in Theoretical Computer Science. Amsterdam: Elsevier Science.Google Scholar
Reynolds, John C. (1972) Definitional interpreters for higher-order programming languages. In Proceedings of the ACM National Conference, vol. 2. New York: ACM, pp. 717740. Reprinted with a foreword in Higher-Order Symbol. Comput. 11(4), 363–397.Google Scholar
Reynolds, John C. (1974) On the relation between direct and continuation semantics. In Automata, Languages and Programming: 2nd Colloquium. Loeckx, Jacques (ed). Lecture Notes in Computer Science, vol. 14, Berlin: Springer-Verlag, pp. 141156.CrossRefGoogle Scholar
Reynolds, John C. (1975) User-defined types and procedural data structures as complementary approaches to data abstraction. In New Directions in Algorithmic Languages 1975. Schuman, Stephen A. (ed). IFIP Working Group 2.1 on Algol, Rocquencourt, France: INRIA, pp. 157168.Google Scholar
Rhiger, Morten (2001) Higher-Order program generation. Ph.D. Thesis, BRICS Ph.D. School. Department of Computer Science, University of Aarhus, Denmark.Google Scholar
Shao, Zhong (1998) Typed cross-module compilation. In ICFP 1998: Proceedings of the ACM International Conference on Functional Programming, vol. 34(1) of ACM SIGPLAN Notices. New York: ACM, pp. 141152.Google Scholar
Shao, Zhong, Trifonov, Valery, Saha, Bratin & Papaspyrou, Nikolaos S. (2005) A type system for certified binaries. ACM Trans. Prog. Lang. Sys. 27 (1): 145.CrossRefGoogle Scholar
Sheard, Tim & PeytonJones, Simon L. Jones, Simon L. (2002) Template meta-programming for Haskell. In Proceedings of the 2002 Haskell workshop, Chakravarty, Manuel M. T. (ed). New York: ACM, pp. 116.Google Scholar
Sperber, Michael (1996) Self-applicable online partial evaluation. In Partial Evaluation, Danvy, Olivier, Glück, Robert, and Thiemann, Peter (eds). Lecture Notes in Computer Science, vol. 1110. Schloß Dagstuhl, Germany: Springer-Verlag, pp. 465480.CrossRefGoogle Scholar
Sperber, Michael & Thiemann, Peter (1997) Two for the price of one: Composing partial evaluation and compilation. In PLDI 97: Proceedings of the ACM Conference on Programming Language Design and Implementation. New York: ACM, pp. 215225.CrossRefGoogle Scholar
Sumii, Eijiro & Kobayashi, Naoki (2001) A hybrid approach to online and offline partial evaluation. Higher-Order Symbol. Comput. 14 (2–3), 101142.CrossRefGoogle Scholar
Taha, Walid (1999) A sound reduction semantics for untyped CBN multi-stage computation. or, the theory of MetaML is non-trival (extended abstract). In Proceedings of the 2000 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, Lawall, Julia L. (ed). ACM SIGPLAN Notices, vol. 34(11) New York: ACM Press, pp. 3443.CrossRefGoogle Scholar
Taha, Walid, Makholm, Henning & Hughes, John (2001) Tag elimination and Jones-optimality. In Proceedings of PADO 2001: 2nd Symposium on Programs as Data Objects, Danvy, Olivier and Filinski, Andrzej (eds). Lecture Notes in Computer Science, vol. 2053, Berlin: Springer-Verlag, pp. 257275.Google Scholar
Taha, Walid & Nielsen, Michael Florentin (2003) Environment classifiers. In POPL 03: Conference Record of the Annual ACM Symposium on Principles of Programming Languages. New York: ACM, pp. 2637.CrossRefGoogle Scholar
Thiemann, Peter (1999) Combinators for program generation. J. Funct. Prog 9 (5), 483525.CrossRefGoogle Scholar
Thiemann, Peter & Sperber, Michael (1997) Program generation with class. In Proceedings Informatik 97, Jarke, M., Pasedach, K., and Pohl, K. (eds). Reihe Informatik aktuell, Aachen: Springer-Verlag, pp. 582592.Google Scholar
Washburn, Geoffrey Alan & Weirich, Stephanie (2008) Boxes go bananas: Encoding higher-order abstract syntax with parametric polymorphism. J. Funct. Prog. 18 (1), 87140.CrossRefGoogle Scholar
Xi, Hongwei, Chen, Chiyan & Chen, Gang (2003) Guarded recursive datatype constructors. In POPL 03: Conference Record of the Annual ACM Symposium on Principles of Programming Languages. New York: ACM, pp. 224235.CrossRefGoogle Scholar
Yang, Zhe (2004) Encoding types in ML-like languages. Theor. Comp. Sci. 315 (1), 151190.CrossRefGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.
You have Access
151
Cited by

Save article to Kindle

To save this article to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages
Available formats
×

Save article to Dropbox

To save this article to your Dropbox account, please select one or more formats and confirm that you agree to abide by our usage policies. If this is the first time you used this feature, you will be asked to authorise Cambridge Core to connect with your Dropbox account. Find out more about saving content to Dropbox.

Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages
Available formats
×

Save article to Google Drive

To save this article to your Google Drive account, please select one or more formats and confirm that you agree to abide by our usage policies. If this is the first time you used this feature, you will be asked to authorise Cambridge Core to connect with your Google Drive account. Find out more about saving content to Google Drive.

Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages
Available formats
×
×

Reply to: Submit a response

Please enter your response.

Your details

Please enter a valid email address.

Conflicting interests

Do you have any conflicting interests? *