Under Consideration for Publication in J. Functional Programming Embedded Interpreters

This is a tutorial on using type-indexed embedding/projection pairs when writing interpreters in statically-typed functional languages. The method allows (higher-order) values in the interpreting language to be embedded in the interpreted language and values from the interpreted language may be projected back into the interpreting one. This is particularly useful when adding command-line interfaces or scripting languages to applications written in functional languages. We first describe the basic idea and show how it may be extended to languages with recursive types and applied to elementary meta-programming. We then show how the method combines with Filinski's continuation-based monadic reflection operations to define an lextensionalr version of the call-by-value monadic translation and hence to allow values to be mapped bidirectionally between the levels of an interpreter for a functional language parameterized by an arbitrary monad. Finally, we show how SML functions may be embedded into, and projected from, an interpreter for an asynchronous $\pi$-calculus via an ‘extensional’ variant of a standard translation from $\lambda$ into $\pi$.

[1]  Paul Hudak,et al.  Modular domain specific languages and tools , 1998, Proceedings. Fifth International Conference on Software Reuse (Cat. No.98TB100203).

[2]  Kristoffer Hogsbro Rose,et al.  Type-Directed Partial Evaluation in Haskell , 1998 .

[3]  Gerald J. Sussman,et al.  Structure and interpretation of computer programs , 1985, Proceedings of the IEEE.

[4]  Andrew Kennedy,et al.  Pickler combinators , 2004, J. Funct. Program..

[5]  Dana S. Scott,et al.  Data Types as Lattices , 1976, SIAM J. Comput..

[6]  Olivier Danvy Functional Unparsing , 1998, J. Funct. Program..

[7]  Fritz Henglein Dynamic Typing , 1992, ESOP.

[8]  Morten Rhiger,et al.  A foundation for embedded languages , 2002, TOPL.

[9]  Mario Tokoro,et al.  An Object Calculus for Asynchronous Communication , 1991, ECOOP.

[10]  Robin Milner,et al.  Functions as processes , 1990, Mathematical Structures in Computer Science.

[11]  Kazuhiko Kato,et al.  Semantics for communication primitives in a polymorphic language , 1993, POPL '93.

[12]  Olin Shivers A Universal Scripting Framework or Lambda: The Ultimate "Little Language" , 1996, ASIAN.

[13]  Arie van Deursen,et al.  Domain-specific languages: an annotated bibliography , 2000, SIGP.

[14]  Benjamin C. Pierce,et al.  Pict: a programming language based on the Pi-Calculus , 2000, Proof, Language, and Interaction.

[15]  Zhe Yang,et al.  Encoding types in ML-like languages , 1998, ICFP '98.

[16]  Stephanie Weirich,et al.  Type-safe cast: (functional pearl) , 2000, ICFP '00.

[17]  Robin Milner,et al.  A Calculus of Mobile Processes, II , 1992, Inf. Comput..

[18]  Norman Ramsey ML Module Mania: A Type-Safe, Separately Compiled, Extensible Interpreter , 2006, Electron. Notes Theor. Comput. Sci..

[19]  Patrick Cousot,et al.  Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints , 1977, POPL.

[20]  John K. Ousterhout,et al.  Scripting: Higher-Level Programming for the 21st Century , 1998, Computer.

[21]  Olivier Danvy,et al.  A Simple Solution to Type Specialization , 1998, ICALP.

[22]  Guy L. Steele,et al.  Building interpreters by composing monads , 1994, POPL '94.

[23]  Gérard Boudol The π-calculus in direct style , 1997, POPL '97.

[24]  Robert Harper,et al.  Compiling polymorphism using intensional type analysis , 1995, POPL '95.

[25]  Peter Lee,et al.  Optimizing ML with run-time code generation , 1996, SIGP.

[26]  Nancy Jean Mccracken,et al.  An investigation of a programming language with a polymorphic type structure. , 1979 .

[27]  Olivier Danvy,et al.  Type-directed partial evaluation , 1995, POPL '96.

[28]  Philip Wadler,et al.  Linear logic, monads and the lambda calculus , 1996, Proceedings 11th Annual IEEE Symposium on Logic in Computer Science.

[29]  Philip Wadler,et al.  The essence of functional programming , 1992, POPL '92.

[30]  Robin Milner,et al.  Communicating and mobile systems - the Pi-calculus , 1999 .

[31]  Eugenio Moggi,et al.  Notions of Computation and Monads , 1991, Inf. Comput..

[32]  Zhong Shao,et al.  Fully reflexive intensional type analysis , 2000, ICFP '00.

[33]  Davide Sangiorgi The Lazy Lambda Calculus in a Concurrency Scenario , 1994, Inf. Comput..

[34]  M.N. Sastry,et al.  Structure and interpretation of computer programs , 1986, Proceedings of the IEEE.

[35]  Walid Taha,et al.  MetaML and multi-stage programming with explicit annotations , 2000, Theor. Comput. Sci..

[36]  John C. Reynolds,et al.  The Meaning of Types From Intrinsic to Extrinsic Semantics , 2000 .

[37]  Jim Hugunin Python and Java: The Best of Both Worlds , 1997 .

[38]  Jon Louis Bentley,et al.  Programming pearls: little languages , 1986, CACM.

[39]  Nick Benton,et al.  Monads and Effects , 2000, APPSEM.

[40]  Xavier Leroy,et al.  Unboxed objects and polymorphic typing , 1992, POPL '92.

[41]  Robin Milner,et al.  A Calculus of Mobile Processes, II , 1992, Inf. Comput..

[42]  Andrzej Filinski,et al.  Representing layered monads , 1999, POPL '99.

[43]  Olivier Danvy A Simple Solution to Type Specialization , 1998 .

[44]  Nick Benton,et al.  Compiling standard ML to Java bytecodes , 1998, ICFP '98.

[45]  Davide Sangiorgi,et al.  The Pi-Calculus - a theory of mobile processes , 2001 .

[46]  Konrad Slind OBJECT LANGUAGE EMBEDDING IN STANDARD ML OF NEW JERSEY , 1991 .

[47]  Mitchell Wand,et al.  Continuation-Based Multiprocessing , 1980, High. Order Symb. Comput..

[48]  John H. Reppy,et al.  Concurrent programming in ML , 1999 .

[49]  Guido Rossum,et al.  Extending and embedding the python interpreter , 1995 .

[50]  Norman Ramsey,et al.  Embedding an interpreted language using higher-order functions and types , 2003, IVME '03.

[51]  Gerald J. Sussman,et al.  Structure and Interpretation of Computer Programs, Second Edition , 1996 .

[52]  Philip Wadler,et al.  A Semi-monad for Semi-structured Data , 2001, ICDT.

[53]  Emir Pasalic,et al.  Two-level types and parameterized modules , 2004, Journal of Functional Programming.

[54]  Paul Hudak,et al.  Monad transformers and modular interpreters , 1995, POPL '95.

[55]  Zhe Yang Encoding types in ML-like languages , 2004, Theor. Comput. Sci..

[56]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[57]  Stephanie Weirich Type-FUNCTIONAL PEARL safe cast , 2004 .

[58]  John C. Reynolds,et al.  Definitional Interpreters for Higher-Order Programming Languages , 1972, ACM '72.

[59]  Stephanie Weirich,et al.  Encoding Intensional Type Analysis , 2001, ESOP.

[60]  Paul Hudak,et al.  Modular Denotational Semantics for Compiler Construction , 1996, ESOP.

[61]  John C. Reynolds Definitional Interpreters for Higher-Order Programming Languages , 1998, High. Order Symb. Comput..

[62]  Matthias Felleisen,et al.  Contracts for higher-order functions , 2002, ICFP '02.