Skip to main content
Log in

Improving the lazy Krivine machine

  • Published:
Higher-Order and Symbolic Computation

Abstract

Krivine presents the \(\mathcal {K}\)  machine, which produces weak head normal form results. Sestoft introduces several call-by-need variants of the \({\mathcal {K}}\)  machine that implement result sharing via pushing update markers on the stack in a way similar to the TIM and the STG machine. When a sequence of consecutive markers appears on the stack, all but the first cause redundant updates. Improvements related to these sequences have dealt with either the consumption of the markers or the removal of the markers once they appear. Here we present an improvement that eliminates the production of marker sequences of length greater than one. This improvement results in the \({\mathcal {C}}\)  machine, a more space and time efficient variant of \({\mathcal {K}}\) .

We then apply the classic optimization of short-circuiting operand variable dereferences to create the call-by-need \({\mathcal {S}}\)  machine. Finally, we combine the two improvements in the \({\mathcal {CS}}\)  machine. On our benchmarks this machine uses half the stack space, performs one quarter as many updates, and executes between 27% faster and 17% slower than our ℒ variant of Sestoft’s lazy Krivine machine. More interesting is that on one benchmark ℒ, \({\mathcal {S}}\) , and \({\mathcal {C}}\) consume unbounded space, but \({\mathcal {CS}}\) consumes constant space. Our comparisons to Sestoft’s Mark 2 machine are not exact, however, since we restrict ourselves to unpreprocessed closed lambda terms. Our variant of his machine does no environment trimming, conversion to deBruijn-style variable access, and does not provide basic constants, data type constructors, or the recursive let. (The Y combinator is used instead.)

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

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Institutional subscriptions

Similar content being viewed by others

References

  1. Abelson, H., Sussman, G.J.: The Structure and Interpretation of Computer Programs. MIT Press, Cambridge (1985)

    Google Scholar 

  2. Ager, M.S., Biernacki, D., Danvy, O., Midtgaard, J.: From interpreter to compiler and virtual machine: a functional derivation. Technical Report RS-03-14, 36 pp. (2003)

  3. Ager, M.S., Biernacki, D., Danvy, O., Midtgaard, J.: A functional correspondence between evaluators and abstract machines. In: International Conference on Principles and Practice of Declarative Programming, pp. 8–19 (2003)

  4. Ager, M.S., Danvy, O., Midtgaard, J.: A functional correspondence between call-by-need evaluators and lazy abstract machines. Technical Report RS-03-24, 13 pp. (2003)

  5. Ager, M.S., Danvy, O., Midtgaard, J.: A functional correspondence between monadic evaluators and abstract machines for languages with computational effects. Technical Report RS-03-35, 31 pp. (2003)

  6. Argo, G.: Improving the three instruction machine. In: Fourth International Conference on Functional Programming Languages and Computer Architecture, Reading, MA, pp. 100–112 (1989)

  7. Barendregt, H.P.: The Lambda Calculus: Its Syntax and Semantics. North-Holland, Amsterdam (1981)

    MATH  Google Scholar 

  8. Clements, J., Felleisen, M.: A tail-recursive semantics for stack inspections. In: European Symposium on Programming (2003)

  9. Crégut, P.: An abstract machine for the normalization of λ-terms. In: Proc. 1990 ACM Symposium on Lisp and Functional Programming, pp. 333–340 (1990)

  10. Crégut, P.: Machines à environment pour la réduction symbolique et l’évaluation partielle. Ph.D. Thesis, Université de Paris VII, Paris, France (1991)

  11. Danvy, O.: A lambda-revelation of the SECD machine. Technical Report RS-02-53, 15 pp. (2003). Superseeded by the BRICS report RS-03-33

  12. Danvy, O.: A rational deconstruction of Landin’s SECD machine. Technical Report RS-03-33, 32 pp. (2003). This report supersedes the earlier BRICS report RS-02-53

  13. Fairbairn, J., Wray, S.C.: Tim: a simple lazy abstract-machine to execute supercombinators. In: G. Kahn (ed.) IFIP Functional Programming Languages and Computer Architecture, pp. 34–45 (1987)

  14. Krivine, J.-L.: Un interprète du λ-calcul (1985)

  15. Launchbury, J.: A natural semantics for lazy evaluation. In: Conference Record of the Twentieth Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Charleston, South Carolina, pp. 144–154 (1993)

  16. Launchbury, J., Gill, A., Hughes, J., Marlow, S., Peyton Jones, S., Wadler, P.: Avoiding unnecessary updates. In: J. Launchbury and P.M. Sansom (eds.) Functional Programming, Glasgow, 1992

  17. Mycroft, A.: Abstract interpretation and optimising transformations for applicative programs. Ph.D. Thesis, University of Edinburgh, Edinburgh, Scotland (1981)

  18. Péter, R.: Recursive Functions. Academic, New York (1967)

    MATH  Google Scholar 

  19. Peyton Jones, S.L.: Implementing lazy functional languages on stock hardware: the spineless tagless G-machine. J. Funct. Program. 2(2), 127–202 (1992)

    Article  MATH  Google Scholar 

  20. Randell, B., Russell, L.J.: Algol 60 Implementation. Academic, New York (1964)

    MATH  Google Scholar 

  21. Reinke, C.: GHood–graphical visualisation and animation of Haskell object observations. In: R. Hinze (ed.) Haskell Workshop (2001)

  22. Reynolds, J.C.: Definitional interpreters for higher-order programming languages. In: Proceedings ACM National Conference, pp. 717–740 (1972)

  23. Sestoft, P.: Deriving a lazy abstract machine. J. Funct. Program. 7(3), 231–264 (1997)

    Article  MATH  MathSciNet  Google Scholar 

  24. Steel, T.B. (ed.): Formal Language Description Languages for Computer Programming. North-Holland, Amsterdam (1966)

    MATH  Google Scholar 

  25. Wakeling, D., Dix, A.: Optimising partial applications in TIM, Technical Report, University of York (1993)

  26. Wand, M.: On the correctness of the Krivine machine. Higher-Order Symb. Comput. Special issue on Krivine’s abstract machine (2007)

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Daniel P. Friedman.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Friedman, D.P., Ghuloum, A., Siek, J.G. et al. Improving the lazy Krivine machine. Higher-Order Symb Comput 20, 271–293 (2007). https://doi.org/10.1007/s10990-007-9014-0

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10990-007-9014-0

Keywords

Navigation