Abstract
Partially-static data structures are a well-known technique for improving binding times. However, they are often defined in an ad-hoc manner, without a unifying framework to ensure full use of the equations associated with each operation. We present a foundational view of partially-static data structures as free extensions of algebras for suitable equational theories, i.e. the coproduct of an algebra and a free algebra in the category of algebras and their homomorphisms. By precalculating these free extensions, we construct a high-level library of partially-static data representations for common algebraic structures. We demonstrate our library with common use-cases from the literature: string and list manipulation, linear algebra, and numerical simplification.
Highlights
The defining feature of multi-stage programming is putting fine-grained control over beta reduction in the hands of the programmer
How might we build implementations of algebraic operations that support computation with partially-static data? This section sketches a general approach to defining these partially-static algebras that can be used as drop-in replacements for standard instances in type-class polymorphic code. ğ4 describes the implementation of this approach as a high-level, modular and extensible library, which applies directly to several examples drawn from the literature
Unifying: Partially-static data is a well-known technique for binding-time improvement, and ad-hoc implementations of structures that implement some algebraic simplifications are found throughout the literature (ğ7)
Summary
The defining feature of multi-stage programming is putting fine-grained control over beta reduction in the hands of the programmer. We might post-process generated code to perform algebraic simplifications This risks giving up the most desirable properties of multi-stage programming: namely that code transformations can be implemented by the programmer within the language itself. We might introduce specialized numeric representations that simplify generated code using laws of the underlying algebraic structure This is, in our view, the most promising approach, and is widely used in the multi-stage programming literature (ğ7). In each case we illustrate the structures with examples drawn from the literature, showing how frex can be applied to programming problems such as arithmetic, pretty-printing, linear algebra and list manipulation, to improve generated code by algebraic simplifications. Ğ7 contextualizes our contributions among the work on partially-static data
Talk to us
Join us for a 30 min session where you can share your feedback and ask us any queries you have