A Lightweight Optimization Technique for Data Types a la Carte

Data types à la carte (DTC) is a technique for adding new variants to data types modularly. A drawback of DTC compared with simple variant types, which are commonly used to define data types in functional programming languages, is runtime inefficiency caused by the destruction of these values. In this paper, we propose a lightweight optimization technique for functions that destruct the values of DTC data types. It makes their execution as efficient as their non-DTC counterparts by just (1) deriving non-extensible algebraic data types isomorphic to ex- tensible data types defined in DTC fashion and (2) using them within the type annotations that specify concrete data types using the composition operator given in DTC. The approach is based on an insight on the functions: the functions never depend on any con- crete data types but merely constrain them. We implemented functions that take an extensible data type defined in DTC fashion and derive an isomorphic non-extensible algebraic data type using Template Haskell. Our experimental re- sults show that DTC functions using our approach run as efficiently as their non-DTC counterparts and avoid performance slow down even if the data types are extended multiple times.

[1]  Patrick Bahr Composing and decomposing data types: a closed type families implementation of data types à la carte , 2014, WGP '14.

[2]  Peter Gammie,et al.  The Worker/Wrapper Transformation , 2009, Arch. Formal Proofs.

[3]  Wouter Swierstra,et al.  Data types à la carte , 2008, Journal of Functional Programming.

[4]  Emir Pasalic,et al.  Two-level types and parameterized modules , 2004, Journal of Functional Programming.