Abstract
We present a technique for compiling lambda-calculus expressions into SKI combinators. Unlike the well-known bracket abstraction based on (syntactic) term re-writing, our algorithm relies on a specially chosen, compositional semantic model of generally open lambda terms. The meaning of a closed lambda term is the corresponding SKI combination. For simply-typed as well as unityped terms, the meaning derivation mirrors the typing derivation. One may also view the algorithm as an algebra, or a non-standard evaluator for lambda-terms (i.e., denotational semantics).
The algorithm is implemented as a tagless-final compiler for (uni)typed lambda-calculus embedded as a DSL into OCaml. Its type preservation is clear even to OCaml. The correctness of both the algorithm and of its implementation becomes clear.
Our algorithm is easily amenable to optimizations. In particular, its output and the running time can both be made linear in the size (i.e., the number of all constructors) of the input De Bruijn-indexed term.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
By ‘weakening’ we mean a (structural) inference rule stating that adding more premises to hypotheses of a valid logical deduction preserves the validity.
- 2.
As we will see in Sect. 6, it is enough to keep the length of \(\varGamma \), that is, the number of free variables in a term.
- 3.
It is natural to wish a denotation of an open term be non-divergent: if \(\tau _n,\ldots ,\tau _1\models d\) then d, until applied to n other terms, should have only a finite number of reductions, if any at all. The wish is already granted: in the present simply-typed calculus, all terms are (strongly) normalizing. We have to wait until Sect. 6 to say something non-trivial about termination.
- 4.
The optimal solution is described in Sect. 6.
- 5.
- 6.
It is worth pointing out one, comprehensive web page: http://www.cantab.net/users/antoni.diller/brackets/intro.html.
References
Carette, J., Kiselyov, O., Shan, C.C.: Finally tagless, partially evaluated: tagless staged interpreters for simpler typed languages. J. Funct. Program. 19(5), 509–543 (2009)
Curry, H.B., Feys, R.: Combinatory Logic. North-Holland, Amsterdam (1958)
Hughes, R.J.M.: Super combinators: a new implementation method for applicative languages. In: Symposium on LISP and Functional Programming, pp. 1–10. ACM, August 1982
Joy, M.S., Rayward-Smith, V.J., Burton, F.W.: Efficient combinator code. Comput. Lang. 10(3/4), 211–224 (1985)
Kiselyov, O.: Typed Tagless Final Interpreters. In: Gibbons, J. (ed.) Generic and Indexed Programming. LNCS, vol. 7470, pp. 130–174. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-32202-0_3
Noshita, K.: Translation of Turner combinators in O(n log n) space. Inf. Process. Lett. 20(2), 71–74 (1985)
Peyton Jones, S.: The Implementation of Functional Programming Languages. Prentice Hall, Upper Saddle River, January 1987. https://www.microsoft.com/en-us/research/publication/the-implementation-of-functional-programming-languages/
Schönfinkel, M.: Über die Bausteine der mathematischen Logik. Math. Ann. 92(3), 305–316 (1924)
Sinot, F.R.: Director strings revisited: a generic approach to the efficient representation of free variables in higher-order rewriting. J. Log. Comput. 15(2), 201–218 (2005)
Sørensen, M.H., Urzyczyn, P.: Lectures on the Curry-Howard isomorphism. Technical report 98/14 (TOPPS note D-368), DIKU, Copenhagen (1998)
Stoye, W.R.: The implementation of functional languages using custom hardware. Ph.D. thesis, Computer Laboratory, University of Cambridge, December 1985. http://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-81.pdf
Turner, D.A.: Another algorithm for bracket abstraction. J. Symb. Log. 44(2), 267–270 (1979)
Turner, D.A.: A new implementation technique for applicative languages. Softw.-Pract. Exp. 9, 31–49 (1979)
Acknowledgments
I thank Yukiyoshi Kameyama for his challenge to write the SK conversion in the tagless-final style, and helpful discussions. I am very grateful to Doaitse Swierstra, Fritz Henglein and Noam Zeilberger for many helpful comments and discussions. Numerous suggestions by anonymous reviewers have greatly helped improve the presentation.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2018 Springer International Publishing AG, part of Springer Nature
About this paper
Cite this paper
Kiselyov, O. (2018). \(\lambda \) to SKI, Semantically. In: Gallagher, J., Sulzmann, M. (eds) Functional and Logic Programming. FLOPS 2018. Lecture Notes in Computer Science(), vol 10818. Springer, Cham. https://doi.org/10.1007/978-3-319-90686-7_3
Download citation
DOI: https://doi.org/10.1007/978-3-319-90686-7_3
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-90685-0
Online ISBN: 978-3-319-90686-7
eBook Packages: Computer ScienceComputer Science (R0)