Abstract

Abbott et al.'s notion of containers characterises a subset of parametric data types which can be described by a set of shapes and set of positions for each shape. This captures common data types such as tuples, lists, trees, arrays, and graphs. Various useful categorical structures can be derived for containers given additional information. For example, directed containers give rise to container comonads (Ahman et al.). Containers provide a useful reasoning principle and asbtraction mechanism for programming. This paper studies the performance characteristics of traversal schemes over containers, modelled by functor and comonad structures. A cost model for container transformations is defined from which complexity bounds for the operations of container functors and comonads are derived. These bounds suggest optimisations for programs structured using these idioms. The abstract interface provided by the syntax of containers and category theory provides complexity bounds and subsequent optimisations that are implementation agnostic (machine free).

Highlights

  • Consider the following two program fragments, written in some imperative language, where A, B, and C are one-dimensional arrays and f and g are pure functions: for i = 1..n for i = 1..n for u = 1..n B(i) = f(A, i)B(u) = f(A, u) for i = 1..n C(i) = g(B, i) (1)The two programs are extensionally equivalent; given the same inputs, they compute the same result

  • The two programs are not intensionally equivalent; the left-hand program has worse performance. This inefficiency is revealed by an execution-time analysis

  • The left program has execution time ∈ O(n2[f] + n[g]) where the nested loop for f performs redundant recomputation. Given this computational complexity information, it would be reasonable for an optimising compiler to transform the left program into the right, since this leads to a potential asymptotic improvement

Read more

Summary

Introduction

The left program has execution time ∈ O(n2[f] + n[g]) where the nested loop for f performs redundant recomputation Given this computational complexity information, it would be reasonable for an optimising compiler to transform the left program into the right, since this leads to a potential asymptotic improvement. We study functors since they capture the common programming pattern of an element-wise traversal of a data structure, e.g., the map function on lists, or transforming every element of an array [21]. Our general motivation is to provide a basis for deriving compiler optimisations on containerbased programs To this end, we consider two varieties of functor/comonad structure throughout: (1) those derived from (directed) container structures and (2) those that are abstract (non-derived), where the implementation is unknown (as in an abstract data type).

Containers
Functors
Container comonads
Abstract container comonads
Related work
Discussion and conclusion
Full Text
Paper version not known

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

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.