Abstract
A criticism often levelled at functional languages is that they do not cope elegantly or efficiently with problems involving changes of state. In a recent paper [26], Wadler has proposed a new approach to these problems. His proposal involves the use of a type system based on the linear logic of Girard [7]. This allows the programmer to specify the “natural” imperative operations without at the same time sacrificing the crucial property of referential transparency.
In this paper we investigate the practicality of Wadler's approach, describing the design and implementation of a variant of Lazy ML [2]. A small example program shows how imperative operations can be used in a referentially transparent way, and at the same time it highlights some of the problems with the approach. Our implementation is based on a variant of the G-machine [15, 1]. We give some benchmark figures to compare the performance of our machine with the original one. The results are disappointing: the cost of maintaining linearity in terms of lost optimisations at compile-time, and the extra data structures that must be created at run-time more than cancels out the gains made by using linear types to reduce the amount of garbage collection. We also consider how the language and the implementation can be extended to accommodate aggregates such as arrays. Here the results are more promising: linear arrays are usually more efficient than trailered ones, but they are less efficient than destructively-updated ones. We conclude that larger aggregates are the most promising area of application for Wadler's type system.
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
L. Augustsson. Compiling Lazy Functional Languages, Part II. PhD thesis, Chalmers University of Technology, S-412 96 Göteborg, November 1987.
L. Augustsson and T. Johnsson. Lazy ML Users Manual, July 1989. (Distributed with the LML compiler, version 0.95).
A. Bloss. Update analysis and the efficient implementation of functional aggregates. In Proceedings of the 1989 Conference on Functional Programming Languages and Computer Architecture, pages 26–38. ACM Press, September 1989.
G. Cousineau, P.-L. Curien, and M. Mauny. The categorical abstract machine. Science of Computer Programming, 8:173–202, 1987.
J. Fairbairn and S. Wray. TIM: A simple, lazy abstract machine to execute supercombinators. In Proceedings of the 1987 Conference on Functional Programming Languages and Computer Architecture, pages 34–45. Springer-Verlag, September 1987. LNCS 274.
R. R. Fenichel and J. C. Yochelson. A LISP garbage-collector for virtual-memory computer systems. CACM, 12(11):611–612, November 1969.
J.-Y. Girard. Linear logic. Theoretical Computer Science, 50(1):1–101, 1987.
J.-Y. Girard and Y. Lafont. Linear logic and lazy computation. In Proceedings of the International Joint Conference on Theory and Practice of Software Development (TAPSOFT'87), pages 52–66. Springer-Verlag, March 1987. LNCS 250.
J. C. Guzmán and P. Hudak. Single-threaded polymorphic lambda calculus. In Proceedings of the Fifth Annual IEEE Symposium on Logic In Computer Science, pages 333–343, June 1990.
S. Holmström. A simple and efficient way to handle large data structures in applicative languages. In Proceedings of the SERC/Chalmers Workshop on Declarative Programming, pages 185–187. University College London, April 1983.
S. Holmström. A linear functional language. In Proceedings of the Workshop on the Implementation of Lazy Functional Languages, Aspenäes, pages 13–32, September 1988. Report 53, Programming Methodology Group, Chalmers University of Technology, S-412 96 Göteborg.
S. Holmström. Quicksort in a linear functional language. PMG Memo. 65, Chalmers University of Technology, S-412 96 Göteborg, January 1989.
P. Hudak. A semantic model of reference counting and its abstraction. In S. Abramsky and C. Hankin, editors, Abstract Interpretation of Declarative Languages, pages 45–62. Ellis Horwood, 1987.
P. Hudak and P. Wadler (editors). Report on the programming language Haskell, a non-strict purely functional language (Version 1.0). Technical report, University of Glasgow, Department of Computer Science, April 1990.
T. Johnsson. Compiling Lazy Functional Languages. PhD thesis, Chalmers University of Technology, S-412 96 Göteborg, February 1987.
Y. Lafont. The linear abstract machine. Theoretical Computer Science, 59:157–180, 1988.
Y. Lafont. Logiques, Catégories et machines. PhD thesis, Université de Paris 7, 1988.
P. J. Landin. The mechanical evaluation of expressions. Computer Journal, 6(4):308–320, 1964.
B. B. Mandelbrot. The Fractal Geometry of Nature. W. H. Freeman, 1983.
R. Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17(3):348–375, 1978.
S. L. Peyton Jones. The Implementation of Functional Programming Languages. Prentice-Hall, 1987.
S. L. Peyton Jones and J. Salkild. The Spineless Tagless G-machine. In Proceedings of the 1989 Conference on Functional Programming Languages and Computer Architecture, pages 184–201. ACM Press, September 1989.
D. A. Schmidt. Detecting global variables in denotational specifications. ACM Transactions on Programming Languages and Systems, 7(2):299–310, April 1985.
D. A. Turner. A new implementation technique for applicative languages. SOFTWARE — Practice and Experience, 9(1):31–50, January 1979.
P. Wadler. Is there a use for linear logic? Technical report, Department of Computing Science, University of Glasgow, December 1990.
P. Wadler. Linear types can change the world! In IFIP Working Conference on Programming Concepts and Methods, Sea of Gallilee, Israel, April 1990.
P. Wadler. Private communication, February 1990.
D. Wakeling. Linearity and laziness. DPhil thesis, Department of Computer Science, University of York, November 1990. Technical Report YCST 90/07.
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 1991 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Wakeling, D., Runciman, C. (1991). Linearity and laziness. In: Hughes, J. (eds) Functional Programming Languages and Computer Architecture. FPCA 1991. Lecture Notes in Computer Science, vol 523. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3540543961_11
Download citation
DOI: https://doi.org/10.1007/3540543961_11
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-54396-1
Online ISBN: 978-3-540-47599-6
eBook Packages: Springer Book Archive
Keywords
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.