ABSTRACT
The Scheme programming language has the control constructs: call-with-current-continuation (call/cc) and dynamic-wind. The construct call/cc is a procedure to handle first-class continuations. The construct dynamic-wind is a procedure to hook a continuation captured by call/cc. It can add pre- and post-processing to a continuation, and allows flexible handling of global escape and control effect by continuation calls. The first example where the continuation is applied is rewriting variables with dynamic scope, and the second is saving and restoring registers during context switching of threads implemented in user space.
On the other hand, dynamic-wind is very difficult to understand in Scheme. In fact, the semantics of dynamic-wind represent one of the most complicated mechanisms in Scheme. The semantics presented in the revised Scheme language definition remain complicated, and it is difficult to understand the behavior and write programs correctly. In this article, we focus on three main uses of dynamic-wind: resource allocation at continuous invocation time, and resource release at global escape time. The use of dynamic-wind is focused on resource management, and formalize resource state and resource operations in this paper. For the dynamic-wind modeled in such a way, we propose a type system and an effect system to track the resource state.
In most of the discussions in this paper, we have simplified the model of dynamic-wind to clarify the theory. However, we will show that the method can be applied to more complex situations in practice.
- Yuta Aoyagi and Shin-ya Nishizaki. 2018. Untyped Call-by-Value Calculus with First-Class Continuations and Environments. In Theory and Practice of Computation. World Scientific, 101–117. doi:10.1142/9789813279674_0008.Google Scholar
- H. P. Barendregt. 2013. The Lambda Calculus: Its Sytax and Semantics Revised Edition. North Holland.Google Scholar
- Olivier Danvy and Andrzej Filinski. 1990. Abstracting Control. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming (Nice, France) (LFP ’90). Association for Computing Machinery, New York, NY, USA, 151–160. https://doi.org/10.1145/91556.91622Google ScholarDigital Library
- Marc Feeley. [n.d.]. Scheme Requests for Implementation: SFRI-39. https://srfi.schemers.org/srfi-39/srfi-39.html.Google Scholar
- Mattias Felleisen. [n.d.]. The Theory and Practice of First-Class Prompts. In Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (New York, NY, USA, 1988) (POPL ’88). Association for Computing Machinery, 180–190. https://doi.org/10.1145/73560.73576 event-place: San Diego, California, USA.Google ScholarDigital Library
- M. Felleisen, D. P. Friedman, E. Kohlbecker, and B. Duba. 1986. Reasoning with continuations. In Proceedings of the Symposium on Logic in Computer Science. IEEE Computer Society Press.Google Scholar
- Matthias Felleisen, Daniel P. Friedman, Eugene Kohlbecker, and Bruce Duba. 1987. A syntactic theory of sequential control. Theoretical Computer Science 52, 3 (1987), 205–237. https://doi.org/10.1016/0304-3975(87)90109-5Google ScholarDigital Library
- Martin Gasbichler, Eric Knauel, Michael Sperber, and R. Kelsey. [n.d.]. How to Add Threads to a Sequential Language Without Getting Tangled Up.Google Scholar
- J.-Y. Girard, P. Taylor, and Y. Lafont. 1989. Proofs and Types. Cambridge Tracts in Computer Science, Vol. 7. Cambridge University Press.Google Scholar
- T. G. Griffin. 1990. A Formulae-as-Types Notion of Control. In Conference Record of the Seventeenth Annual ACM Symposium on Principles of Programming Languages.Google ScholarDigital Library
- Christopher T. Haynes and Daniel P. Friedman. [n.d.]. Embedding Continuations in Procedural Objects. 9, 4 ([n. d.]), 582–598. https://doi.org/10.1145/29873.30392 Place: New York, NY, USA Publisher: Association for Computing Machinery.Google ScholarDigital Library
- Pierre Jouvelot and David Gifford. [n.d.]. Algebraic Reconstruction of Types and Effects. In Proceedings of the 18th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (New York, NY, USA, 1991) (POPL ’91). Association for Computing Machinery, 303–310. https://doi.org/10.1145/99583.99623 event-place: Orlando, Florida, USA.Google ScholarDigital Library
- Oleg Kiselyov. [n.d.]. Implementations of delimited control in OCaml, Haskell, Scheme. https://okmij.org/ftp/continuations/implementations.html#dynamic-wind. https://okmij.org/ftp/continuations/implementations.html#dynamic-windGoogle Scholar
- Oleg Kiselyov, Chung-chieh Shan, and Amr Sabry. [n.d.]. Delimited Dynamic Binding. 41, 9([n. d.]), 26–37. https://doi.org/10.1145/1160074.1159808 Place: New York, NY, USA Publisher: Association for Computing Machinery.Google ScholarDigital Library
- S. Nishizaki. 1994. Programs with Continuations and Linear Logic. 21, 2 (1994), 165–190. Elsevier.Google Scholar
- S. Nishizaki. 1995. Simply Typed Lambda Calculus with First-class Environments. Publications of Research Institute for Mathematical Sciences Kyoto University 30, 6 (1995), 1055–1121.Google ScholarCross Ref
- Shin-ya Nishizaki. 2000. A Polymorphic Environment Calculus and its Type Inference Algorithm. Higher-Order and Symbolic Computation 13 (2000), 239–278. Springer.Google ScholarDigital Library
Recommendations
ML Polymorphism of Linear Lambda Calculus with First-class Continuations
ICSCA '19: Proceedings of the 2019 8th International Conference on Software and Computer ApplicationsThe Curry-Howard isomorphism shows that an intuitionistic deductive system is similar to a formal computational system; propositions correspond to types, proofs to lambda-terms, and a proof normalization procedure to an evaluation strategy. Furthermore, ...
Interpretations of the gradually-typed lambda calculus
Scheme '12: Proceedings of the 2012 Annual Workshop on Scheme and Functional ProgrammingGradual typing is an approach to integrating static and dynamic type checking within the same language [Siek and Taha 2006]. Given the name "gradual typing", one might think that the most interesting aspect is the type system. It turns out that the ...
Label dependent lambda calculus and gradual typing
Dependently-typed programming languages are gaining importance, because they can guarantee a wide range of properties at compile time. Their use in practice is often hampered because programmers have to provide very precise types. Gradual typing is a ...
Comments