January 2005
·
29 Reads
·
2 Citations
One of the most attractive features of functional languages is first-class functions. To support first-class functions many functional languages create heap-allocated closures to store the bindings of free variables. This makes it difficult to predict how the heap is accessed and makes accesses to free variables slower than accesses to bound variables. This article presents the operational semantics of the MT evaluator virtual machine and proposes a new implementation strategy for first-class functions in a pure functional language that eliminates the use of heap-allocated closures by using partial evaluation and dynamic code generation. At runtime, functions containing references to free variables are specialized for the bindings of these variables. In these specialized functions, references to free variables become references to constant values. As a result, the need for heap allocated closures is eliminated, accesses to free variables become faster than accesses to bound variables, and expected heap access patterns remain unchanged.