Polymorphic Multi-stage Language with Control Effects

  • Yuichiro Kokaji
  • Yukiyoshi Kameyama
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7078)


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).


Control Effect Operational Semantic Reduction Rule Type Inference Principal Type 
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., Kameyama, Y.: Polymorphic Delimited Continuations. In: Shao, Z. (ed.) APLAS 2007. LNCS, vol. 4807, pp. 239–254. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  2. 2.
    Calcagno, C., Moggi, E., Taha, W.: Ml-Like Inference for Classifiers. In: Schmidt, D. (ed.) ESOP 2004. LNCS, vol. 2986, pp. 79–93. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  3. 3.
    Danvy, O., Filinski, A.: Abstracting control. In: LISP and Functional Programming, pp. 151–160 (1990)Google Scholar
  4. 4.
    Davies, R.: A temporal logic approach to binding-time analysis. In: LICS, pp. 184–195 (1996)Google Scholar
  5. 5.
    Davies, R., Pfenning, F.: A modal analysis of staged computation. Journal of the ACM 48(3), 555–604 (2001)MathSciNetCrossRefzbMATHGoogle Scholar
  6. 6.
    Filinski, A.: Representing Monads. In: Proc. 21st Symposium on Principles of Programming Languages, pp. 446–457 (1994)Google Scholar
  7. 7.
    Kameyama, Y., Kiselyov, O., Shan, C.-c.: Shifting the stage: staging with delimited control. In: PEPM, pp. 111–120 (2009)Google Scholar
  8. 8.
    Kim, I.-S., Yi, K., Calcagno, C.: A polymorphic modal type system for lisp-like multi-staged languages. In: POPL, pp. 257–268 (2006)Google Scholar
  9. 9.
    Kiselyov, O., Shan, C.-c., Sabry, A.: Delimited dynamic binding. In: Reppy, J.H., Lawall, J.L. (eds.) ICFP, pp. 26–37. ACM (2006)Google Scholar
  10. 10.
    Sugiura, K., Kameyama, Y.: Multi-stage language with control effect and code execution. Computer Software Journal of Japan Society of Software Science and Technology 28(1), 217–229 (2011) (in Japanese)Google Scholar
  11. 11.
    Taha, W.: A gentle introduction to multi-stage programming. In: Domain-Specific Program Generation, pp. 30–50 (2003)Google Scholar
  12. 12.
    Taha, W.: A Gentle Introduction to Multi-stage Programming, Part II. In: GTTSE, pp. 260–290 (2007)Google Scholar
  13. 13.
    Taha, W., Nielsen, M.F.: Environment classifiers. In: POPL, pp. 26–37 (2003)Google Scholar
  14. 14.
    Thielecke, H.: From control effects to typed continuation passing. In: POPL, pp. 139–149. ACM Press (2003)Google Scholar
  15. 15.
    Tsukada, T., Igarashi, A.: A logical foundation for environment classifiers. Logical Methods in Computer Science 6(4/9), 1–43 (2010)MathSciNetzbMATHGoogle Scholar
  16. 16.
    Westbrook, E., Ricken, M., Inoue, J., Yao, Y., Abdelatif, T., Taha, W.: Mint: Java multi-stage programming using weak separability. In: PLDI, pp. 400–411 (2010)Google Scholar
  17. 17.
    Yuse, Y., Igarashi, A.: A modal type system for multi-level generating extensions with persistent code. In: PPDP, pp. 201–212 (2006)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2011

Authors and Affiliations

  • Yuichiro Kokaji
    • 1
  • Yukiyoshi Kameyama
    • 1
  1. 1.University of TsukubaJapan

Personalised recommendations