Polymorphic Multi-stage Language with Control Effects

Multi-stage programming (MSP) is a means for run-time code generation, and has been found promising in various fields including numerical computation and domain specific languages. An important problem in designing MSP languages is the dilemma of safety and expressivity; many foundational calculi have been proposed and proven to be type safe, yet, they are not expressive enough. Taha's MetaOCaml provides us a very expressive tool for MSP, yet, the corresponding theory covers its purely functional subset only. In this paper, we propose a polymorphic multi-stage calculus with delimited-control operators. Kameyama, Kiselyov, and Shan proposed a multi-stage calculus with computation effects, but their calculus lacks polymorphism. In the presence of control effects, polymorphism in types is indispensable as all pure functions are polymorphic over answer types, and in MSP languages, polymorphism in stages is indispensable to write custom generators as library functions. We show that the proposed calculus satisfies type soundness and type inference. The former is the key to guarantee the absence of scope extrusion - open codes are never generated or executed. The latter is important in the ML-like programming languages. Following Calcagno, Moggi and Taha's work, we propose a Hindley-Milner style type inference algorithm to obtain principal types for given expressions (if they exist).

[1]  Walid Taha,et al.  A Gentle Introduction to Multi-stage Programming, Part II , 2007, GTTSE.

[2]  Brian Campbell,et al.  Amortised Memory Analysis Using the Depth of Data Structures , 2009, ESOP.

[3]  Walid Taha,et al.  Mint: Java multi-stage programming using weak separability , 2010, PLDI '10.

[4]  Olivier Danvy,et al.  Abstracting control , 1990, LISP and Functional Programming.

[5]  Alexandra Silva,et al.  Non-Deterministic Kleene Coalgebras , 2010, Log. Methods Comput. Sci..

[6]  Rowan Davies,et al.  A temporal-logic approach to binding-time analysis , 1995, Proceedings 11th Annual IEEE Symposium on Logic in Computer Science.

[7]  Hayo Thielecke,et al.  From control effects to typed continuation passing , 2003, POPL '03.

[8]  Chung-chieh Shan,et al.  Shifting the stage - Staging with delimited control , 2011, J. Funct. Program..

[9]  Kwangkeun Yi,et al.  A polymorphic modal type system for lisp-like multi-staged languages , 2006, POPL '06.

[10]  Walid Taha,et al.  A Gentle Introduction to Multi-stage Programming , 2003, Domain-Specific Program Generation.

[11]  Atsushi Igarashi,et al.  A modal type system for multi-level generating extensions with persistent code , 2006, PPDP '06.

[12]  Andrzej Filinski,et al.  Representing monads , 1994, POPL '94.

[13]  Yukiyoshi Kameyama,et al.  Polymorphic Delimited Continuations , 2007, APLAS.

[14]  Atsushi Igarashi,et al.  A Logical Foundation for Environment Classifiers , 2009, TLCA.

[15]  Amr Sabry,et al.  Delimited dynamic binding , 2006, ICFP '06.

[16]  Walid Taha,et al.  Environment classifiers , 2003, POPL.

[17]  Walid Taha,et al.  ML-Like Inference for Classifiers , 2004, ESOP.