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)

Read more

Summary

INTRODUCTION

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

DEFINING PARTIALLY-STATIC STRUCTURES
Partially-Static Data
Coproducts
From Partially-Static to Fully Dynamic
Using frex
INSTANCES AND APPLICATIONS
Coproduct of Monoids
Example
Residualization for Monoids
Coproducts of Commutative Monoids and Abelian Groups
Free Commutative Monoid and Abelian Group
Example: power with Partially-Static Commutative Monoids
4.10 Example
4.12 Example
4.14 Example: all and any with Partially-Static Distributive Lattices
4.15 Coproduct of Initial F-Algebras
4.16 Example
4.17 Practical Considerations
UNIVERSALITY
Rudimentary Universal Algebra
Conceptual Justification
PERFORMANCE EVALUATION
Matrix Multiplication
Printf
RELATED WORK
CONCLUSION AND FURTHER WORK
Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call