Abstract
A selective CPS transformation enables us to execute a program with delimited control operators, \(\texttt {shift}\) and \(\texttt {reset}\), in a standard functional language without support for control operators. The selective CPS transformation dispatches not only on the structure of the input term but also its purity: it transforms only those parts that actually involve control effects. As such, the selective CPS transformation consists of many rules, each for one possible combination of the purity of subterms, making its verification tedious and error-prone. In this paper, we first formalize a monomorphic version of the selective CPS transformation in the Agda proof assistant. We use intrinsically typed term and context representations together with parameterized higher-order abstract syntax (PHOAS) to represent binding structures. We then prove the correctness of the transformation, i.e., the equality of terms is preserved by the CPS transformation. Through the formalization, we confirmed that all the rules of the selective CPS transformation in the previous work are correct, but found that one lemma on the behavior of \(\texttt {shift}\) was not precise.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
PHOAS prevents us from case splitting on the body of an abstraction and a \(\texttt {shift}\) construct until they are applied. It is not a problem for formalizing and verifying CPS transformations.
- 2.
We do not consider let-polymorphism in this paper. See [19] for the formalization of a (non-selective) CPS transformation of lambda calculus (without control operators) extended with let-polymorphism.
- 3.
Following Kameyama and Hasegawa [11], the word ‘pure’ in a pure frame (and a pure context to be introduced soon) is used to mean “no surrounding reset constructs”, not whether control effects are used or not.
- 4.
On the other hand, it looks difficult to prove the progress property in this formalization, because the relational definition of substitution prohibits us from extracting the result of substitution (reduct) from the higher-order representation of a redex. This is not a problem since we do not need the progress property.
- 5.
We conjecture that the same lemma holds not only for a \(\texttt {shift}\) construct but also for an arbitrary expression. We have not formalized the general case yet, however.
References
Altenkirch, T., Reus, B.: Monadic presentations of lambda terms using generalized inductive types. In: Flum, J., Rodriguez-Artalejo, M. (eds.) CSL 1999. LNCS, vol. 1683, pp. 453–468. Springer, Heidelberg (1999). https://doi.org/10.1007/3-540-48168-0_32
Asai, K., Uehara, C.: Selective CPS transformation for shift and reset. In: Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM 2018), pp. 40–52 (2018)
Biernacki, D., Polesiuk, P.: Logical relations for coherence of effect subtyping. Log. Methods Comput. Sci. 14(1), 1–28 (2018)
Chlipala, A.: Parametric higher-order abstract syntax for mechanized semantics. In: Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2008), pp. 143–156, September 2008
Chlipala, A.: Certified Programming with Dependent Types. MIT Press, Cambridge (2013)
Danvy, O., Filinski, A.: A functional abstraction of typed contexts. Technical report 89/12, DIKU, University of Copenhagen, July 1989
Danvy, O., Filinski, A.: Abstracting control. In: Proceedings of the ACM Conference on LISP and Functional Programming (LFP 1990), pp. 151–160 (1990)
Danvy, O., Filinski, A.: Representing control: a study of the CPS transformation. Math. Struct. Comput. Sci. 2(4), 361–391 (1992)
Dargaye, Z., Leroy, X.: Mechanized verification of CPS transformations. In: Dershowitz, N., Voronkov, A. (eds.) LPAR 2007. LNCS (LNAI), vol. 4790, pp. 211–225. Springer, Heidelberg (2007). https://doi.org/10.1007/978-3-540-75560-9_17
Filinski, A.: Representing monads. In: Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 446–457. ACM (1994)
Kameyama, Y., Hasegawa, M.: A sound and complete axiomatization of delimited continuations. In: Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming (ICFP 2003), pp. 177–188 (2003)
Kim, J., Yi, K., Danvy, O.: Assessing the overhead of ML exceptions by selective CPS transformation. In: Proceedings of the 1998 ACM SIGPLAN Workshop on ML, pp. 103–114 (1998)
Lawall, J.L., Danvy, O.: Continuation-based partial evaluation. In: Proceedings of the 1994 ACM Conference on LISP and Functional Programming (LFP 1994), pp. 227–238 (1994)
Materzok, M., Biernacki, D.: Subtyping delimited continuations. In: Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2011), pp. 81–93, September 2011
Minamide, Y., Okuma, K.: Verifying CPS transformations in Isabelle/HOL. In: Proceedings of the 2003 ACM SIGPLAN Workshop on Mechanized Reasoning about Languages with Variable Binding (MERLIN 2003), pp. 1–8 (2003)
Norell, U.: Towards a practical programming language based on dependent type theory. Ph.D. thesis, Chalmers University of Technology, SE-412 96, Göteborg, Sweden, September 2007
Rompf, T., Maier, I., Odersky, M.: Implementing first-class polymorphic delimited continuations by a type-directed selective CPS-transform. In: Proceedings of the 2009 ACM SIGPLAN International Conference on Functional Programming (ICFP 2009), pp. 317–328. ACM (2009)
Tian, Y.H.: Mechanically verifying correctness of CPS compilation. In: Proceeding of the Twelfth Computing: The Australasian Theory Symposium (CATS 2006), vol. 51, pp. 41–51 (2006)
Yamada, U., Asai, K.: Certifying CPS transformation of let-polymorphic calculus using PHOAS. In: Proceedings of the 16th Asian Symposium on Programming Languages and Systems (APLAS 2018), pp. 375–393 (2018)
Acknowledgements
We would like to thank Youyou Cong and anonymous reviewers for valuable comments and feedbacks. This work was partly supported by JSPS KAKENHI under Grant No. JP18H03218.
Author information
Authors and Affiliations
Corresponding authors
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2020 Springer Nature Switzerland AG
About this paper
Cite this paper
Ishio, C., Asai, K. (2020). Verifying Selective CPS Transformation for Shift and Reset. In: Bowman, W., Garcia, R. (eds) Trends in Functional Programming. TFP 2019. Lecture Notes in Computer Science(), vol 12053. Springer, Cham. https://doi.org/10.1007/978-3-030-47147-7_3
Download citation
DOI: https://doi.org/10.1007/978-3-030-47147-7_3
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-47146-0
Online ISBN: 978-3-030-47147-7
eBook Packages: Computer ScienceComputer Science (R0)