\(\lambda \) to SKI, Semantically
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.
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.
- 3.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 1982Google Scholar
- 7.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/
- 10.Sørensen, M.H., Urzyczyn, P.: Lectures on the Curry-Howard isomorphism. Technical report 98/14 (TOPPS note D-368), DIKU, Copenhagen (1998)Google Scholar
- 11.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