Open AccessBook
Implementing Functional Languages: a tutorial
Simon Jones,David Lester +1 more
- 01 Jan 2000
TL;DR: Meachachach et al. as discussed by the authors present a series of implementations of a small functional language called the Core language, which is designed to be as small as possible, but still rich enough to allow modern non-strict functional languages to be translated into it without losing efficiency.
read more
Abstract: This book gives a practical approach to understanding implementations of non-strict functional languages using lazy graph reduction. The book is intended to be a source of practical labwork material, to help make functional-language implementations `come alive’, by helping the reader to develop, modify and experiment with some non-trivial compilers. The unusual aspect of the book is that it is meant to be executed as well as read. Rather than merely presenting an abstract description of each implementation technique, we present the code for a complete working prototype of each major method, and then work through a series of improvements to it. All of the code is available in machine-readable form. Overview of the book The principal content of the book is a series of implementations of a small functional language called the Core language. The Core language is designed to be as small as possible, so that it is easy to implement, but still rich enough to allow modern non-strict functional languages to be translated into it without losing efficiency. It is described in detail in Chapter 1, in which we also develop a parser and pretty-printer for the Core language. Appendix B contains a selection of Core-language programs for use as test programs thoughout the book. The main body of the book consists of four distinct implementations of the Core language. Chapter 2 describes the most direct implementation, based on template instantiation. Chapter 3 introduces the G-machine, and shows how to compile the program to sequences of instructions (G-code) which can be further translated to machine code. Chapter 4 repeats the same exercise for a different abstract machine, the Three Instruction Machine (TIM), whose evaluation model is very different from that of the G-machine. The TIM was developed more recently than the G-machine, so there is much less other literature about it. Chapter 4 therefore contains a rather more detailed development of the TIM’s evaluation model than that given for the G-machine. Finally, Chapter 5 adds a new dimension by showing how to compile functional programs for a parallel G-machine. For each of these implementations we discuss two main parts, the compiler and the machine interpreter. The compiler takes a Core-language program and translates it into a form suitable for execution by the machine interpreter. The machine interpreter simulates the execution of the compiled program. In each case the interpreter is modelled as a state transition system so that there is a very clear connection between the machine interpreter and a `real’ implementation. One important way in which the Core language is restrictive is in its lack of local function definitions. There is a well-known transformation, called lambda lifting, which turns local function definitions into global ones, thus enabling local function definitions to be written freely and transformed out later. In Chapter 6 we develop a suitable lambda lifter. This chapter is more than just a re-presentation of standard material. Full laziness is a property of functional programs which had previously been seen as inseparable from lambda lifting. In Chapter 6 we show that they are in fact quite distinct, and show how to implement full laziness in a separate pass from lambda lifting. Typographical errors Here are some typographical errors, spotted by various readers. Page numbers refer to the online versions (which differ from the printed version). Page 128, second to last paragraph of section 3.7, first sentence. “addis” should be “is a”. Page 134, the code for i’. The “n” under the big brace symbol should say “n pairs”. Page 135. Equation 3.36 should have “NConstr”, not “Constr”. Page 230, second paragraph. “There one final gloss…” should be “There is one final gloss…”. Page 278, the definition of nfib. Replace “n==0” by “n Now, alas, out of print. However the full text of the book is available above. You can order a nicely-bound copy from http://www.cafepress.com/haskell_books. Thanks to John Meacham for setting this up. There is also a tutor’s guide available.
read more
Chat with Paper
AI Agents for this Paper
Find similar papers on Google Scholar, PubMed and Arxiv
Write a critical review of this paper
Analyze citations of this paper to find unaddressed research gaps
Citations
•Dissertation
Optimising the memory management of higher order functional programs
Markus Mohnen
- 01 Jan 1997
TL;DR: This paper focuses on explicit deallocation of heap allocated objects in traditional programming languages like Pascal, C, or Ada, where recursive dynamic data structures like lists or trees are available by explicit access to the heap of the runtime system.
Lazy rewriting on eager machinery
Jasper Kamperman,H. R. Walters +1 more
- 01 Jan 1994
TL;DR: By annotating argument positions as lazy, redundant rewrite steps are avoided, and the termination behavior of a term-rewriting system can be improved.
32
A non-deterministic call-by-need lambda calculus
Arne Kutzner,Manfred Schmidt-Schauß +1 more
- 29 Sep 1998
TL;DR: This paper presents a non-deterministic call-by-need (untyped) lambda calculus λnd with a constant choice and a let-syntax that models sharing that has the nice operational properties of the standard lambda calculus.
Lazy Rewriting and Eager Machinery
J. F. Th. Kamperman,H. R. Walters +1 more
- 05 Apr 1995
TL;DR: Lazy Term Rewriting Systems can be realized by local adaptations of an eager implementation of conventional term rewriting systems and the overhead of lazy evaluation is only incurred when lazy Evaluation is actually performed.
23
References
Lambda lifting: transforming programs to recursive equations
Thomas Johnsson
- 01 Jan 1985
TL;DR: Different ways of doing lambda lifting are presented, as well as reasons for rejecting or selecting the method used in the Lazy ML compiler.
426
Garbage Collection of Linked Data Structures
TL;DR: A concise and unified view of the numerous existing algorithms for performing garbage collection of linked data structures is presented, and the emphasis is on garbage collection proper, rather than on storage allocatlon.
Projections for strictness analysis
Philip Wadler,R. J. M. Hughes +1 more
- 01 Oct 1987
TL;DR: This paper shows how contexts can be represented using the notion of projection from domain theory, which means that recursive context equations can be solved using standard fixpoint techniques, instead of the algebraic manipulation previously used.
TIM: A simple, lazy abstract machine to execute supercombinatorics
John Fairbairn,Stuart C. Wray +1 more
- 14 Sep 1987
TL;DR: The three instruction machine Tim is described, an abstract machine for the execution of supercombinators that usually executes programmes faster than the G-machine style of abstract machine while being at least as easy to implement as an S-K combinator reducer.
Parallel implementations of functional programming languages
TL;DR: In this article, a case study of a particular parallel graph reduction machine and a survey of other parallel architectures is presented. But the main focus of the paper is on the programmer's point of view.
Related Papers (5)
John Fairbairn,Stuart C. Wray +1 more
- 14 Sep 1987
Andrew W. Appel
- 29 Nov 1991
Simon Jones,John Launchbury +1 more
- 26 Aug 1991