Skip to main content

\(\lambda \) to SKI, Semantically

Declarative Pearl

  • Conference paper
  • First Online:
Functional and Logic Programming (FLOPS 2018)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 10818))

Included in the following conference series:

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 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. 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. 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. 4.

    The optimal solution is described in Sect. 6.

  5. 5.

    http://okmij.org/ftp/tagless-final/course/optimizations.html.

  6. 6.

    It is worth pointing out one, comprehensive web page: http://www.cantab.net/users/antoni.diller/brackets/intro.html.

References

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

    Article  MathSciNet  Google Scholar 

  2. Curry, H.B., Feys, R.: Combinatory Logic. North-Holland, Amsterdam (1958)

    MATH  Google Scholar 

  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 1982

    Google Scholar 

  4. Joy, M.S., Rayward-Smith, V.J., Burton, F.W.: Efficient combinator code. Comput. Lang. 10(3/4), 211–224 (1985)

    Article  Google Scholar 

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

    Chapter  Google Scholar 

  6. Noshita, K.: Translation of Turner combinators in O(n log n) space. Inf. Process. Lett. 20(2), 71–74 (1985)

    Article  MathSciNet  Google 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/

  8. Schönfinkel, M.: Über die Bausteine der mathematischen Logik. Math. Ann. 92(3), 305–316 (1924)

    Article  MathSciNet  Google Scholar 

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

    Article  MathSciNet  Google Scholar 

  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

  12. Turner, D.A.: Another algorithm for bracket abstraction. J. Symb. Log. 44(2), 267–270 (1979)

    Article  MathSciNet  Google Scholar 

  13. Turner, D.A.: A new implementation technique for applicative languages. Softw.-Pract. Exp. 9, 31–49 (1979)

    Article  Google Scholar 

Download references

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

Authors

Corresponding author

Correspondence to Oleg Kiselyov .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Springer International Publishing AG, part of Springer Nature

About this paper

Check for updates. Verify currency and authenticity via CrossMark

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)

Publish with us

Policies and ethics