A new programming technique for lazy functional languages (original) (raw)
Related papers
Attribute grammars and functional programming deforestation
Lecture Notes in Computer Science, 1997
The functional programming community is paying increasing attention to static structure-based transformations. For example, generic control operators, such as fold, have been introduced in functional programming to increase the power and applicability of a particular kind of static transformation, called deforestation, which prevents the construction of useless intermediate data structures in function composition. This is achieved by making the structure of the data more explicit in program speci cations. We argue that one of the original concepts of Attribute Grammars is precisely to make data structures explicit in program speci cations. Furthermore, there exists a powerful static deforestation-like transformation in their context. In this paper, we present similarities between deforestation methods, on the one hand with the functional approach, and on the other hand with the Attribute Grammars approach. In order to gain a grasp of these similarities, we rst make a simple comparison: purely-synthesized Attribute Grammars and rst order folds. In this context, deforestation transformations are equivalent. This allows us to highlight the limitations of the fold formalism and to present how the hylomorphism approach generalizes it; hylomorphisms and attribute grammars are surprisingly alike. Finally, we show how the inherited attribute notion in Attribute Grammars solves some transformation problems in higher order functional programs.
The semantics of lazy functional languages
Theoretical Computer Science, 1989
A denotationaf semantics for the A-calculus is described. The semantics is cotinuationbased, and so reflects the order in which expressions are evaluated. It provides a means by which lazy functional languages can be better understood.
The Generalized Intensional Transformation for Implementing Lazy Functional Languages
The intensional transformation is a promising technique for implementing lazy functional languages based on a demand-driven execution model. Despite its theoretical elegance and its simple and efficient execution model, the intensional transformation suffered, until now, from two main drawbacks: (a) it could only be applied to programs that manipulate primitive data-types, and (b) it could only compile a simple (and rather restricted) class of higher-order functions. In this paper we remedy the above two deficiencies, obtaining a transformation algorithm that is applicable to mainstream lazy functional languages. The proposed transformation initially uses defunctionalization in order to eliminate higher-order functions from the source program. The resulting first-order program is then transformed into a program in a simple tuple-based language. Finally, the original intensional transformation is extended in order to be applicable to the tuple language. The correctness of the generalized transformation is formally established. It is demonstrated that the proposed technique can be used to compile a relatively large subset of Haskell into portable C code whose performance is comparable to existing mainstream implementations.
A Lazy to Strict Language Compiler
2017
The evaluation strategies of programming languages can be broadly categorised as strict or lazy. A common approach to strict evaluation is to implement a call-by-value semantics that always evaluates expressions when they are bound to variables, while lazy evaluation is often implemented as call-by-need semantics that evaluates expressions when they are needed for some computation. Lazy semantics makes use of a data structure called thunk that contains an expression, whose evaluation has become suspended, together with its environment. This thesis presents (1) a Haskell definition of the existing semantics of CakeML, a strict programming language, (2) a Haskell definition of a lazy semantics for the pure part of CakeML, and (3) a Haskell implementation of a compiler that compiles lazy CakeML to strict CakeML as defined in (1) and (2). The compiler makes use of stateful features in strict CakeML to optimise evaluation so that each thunk is evaluated at most once, simulating a call-by...
The Gem Cutter is a graphical tool for creating functions in the Haskell-like language CAL by snapping together previously created functions on a canvas known as the table-top. Our contribution is a new graphical model supporting the composition of higherorder functions, creation and use of local functions and variables, composable editors for editing values of possibly compound type, and incorporation of textual CAL expressions. The resulting graphical representation is powerful enough to express any CAL function, but at the same time uses few distinct kinds of graphical elements that are organized as a set of trees rather than a graph. The model is checked by the underlying functional compiler at each stage, ensuring that only valid operations are permitted. The Gem Cutter can suggest valid subsequent compositions to various degrees of granularity. Any part of the model can be run, with value entry for required arguments prompted for using the composable type-directed value editors.
Tracing lazy functional languages
1995
We argue that Ariola and Felleisen's and Maraist, Odersky and Wadler's axiomatization of the call-by-need lambda calculus forms a suitable formal basis for tracing evaluation in lazy functional languages. In particular, it allows a one-dimensional textual representation of terms, rather than requiring a two-dimensional graphical representation using arrows. We describe a program LetTrace, implemented in Gofer and tracing lazy evaluation of a subset of Gofer.
A Technique to Build Debugging Tools for Lazy Functional Logic Languages
Electronic Notes in Theoretical Computer Science, 2009
This paper is based on a recently developed technique to build debugging tools for lazy functional programming languages. With this technique it is possible to replay the execution of a lazy program with a strict semantics by recording information of unevaluated expressions. The recorded information is called an oracle and is very compact. Oracles contain the number of strict steps between discarding unevaluated expressions. The technique has already been successfully employed to construct a debugger for lazy functional languages. This paper extends the technique to include also lazy functional logic languages. A debugging tool built with the technique can be downloaded at www-ps.informatik.uni-kiel.de/~bbr.
Efficient Intensional Implementation for Lazy Functional Languages
Mathematics in Computer Science, 2008
The intensional transformation is a technique that can be used in order to eliminate higher-order functions from a functional program by introducing appropriate context manipulation operators. The transformation can be applied to a significant class of higher-order programs and results in equivalent zero-order intensional programs that can be executed in a simple demand-driven way. Despite its simplicity, the transformation has never been seriously evaluated with respect to its efficiency and potential. Certain simple implementations of the technique have been performed, but the questions regarding the merits of the method have remained inconclusive. In this paper we demonstrate that the transformation can be efficiently implemented by using what we call lazy activation records, namely activation records in which some entries are filled on-demand. An evaluation of our implementation demonstrates that the technique outperforms some of the most well-known functional programming systems, for the class of programs that can be transformed.
Algorithmic debugging for lazy functional languages
Journal of Functional Programming, 1994
Lazy functional languages have non-strict semantics and are purely declarative, i.e. they support the notion of referential transparency and are devoid of side-effects. Traditional debugging techniques are, however, not suited for lazy functional languages since, computations generally do not take place in the order one might expect. Since algorithmic debugging allows the user to concentrate on the declarative aspects of program semantics, and will semi-automatically find functions containing bugs, we propose to use this technique for debugging lazy functional programs. Because of the non-strict semantics of lazy functional languages, arguments to functions are in general partially evaluated expressions. The user is, however, usually more concerned with the values that these expressions represent. We address this problem by providing the user with a strictified view of the execution trace whenever possible. In this paper, we present an algorithmic debugger for a lazy functional language based on strictification and some experience in using it. A number of problems with the current implementation of the debugger (e.g. too large trace size and too many questions asked) are also discussed and some techniques for overcoming these problems, at least partially, are suggested, the key techniques being immediate strictification and piecemeal tracing.