## Algebraic Fusion of Functions with an Accumulating Parameter and Its Improvement

### Cached

### Download Links

Venue: | UNDER CONSIDERATION FOR PUBLICATION IN J. FUNCTIONAL PROGRAMMING |

Citations: | 3 - 0 self |

### BibTeX

@MISC{Katsumata_algebraicfusion,

author = {Shin-ya Katsumata and Susumu Nishimura},

title = { Algebraic Fusion of Functions with an Accumulating Parameter and Its Improvement},

year = {}

}

### OpenURL

### Abstract

This paper develops a new framework for fusion that is designed for eliminating the intermediate data structures involved in the composition of functions that have one accumulating parameter. The new fusion framework comprises two steps: algebraic fusion and its subsequent improvement process. The key idea in our development is to regard functions with an accumulating parameter as functions that operate over the monoid of data contexts. Algebraic fusion composes each such function with a monoid homomorphism that is derived from the definition of the consumer function to obtain a higher-order function that computes over the monoid of endofunctions. The transformation result may be further refined by an improvement process, which replaces the operation over the monoid of endofunctions (i.e., function closures) with another monoid operation over a monoid structure other than function closures. Using our framework, one can formulate a particular solution to the fusion problem by devising appropriate monoids and monoid homomorphisms. This provides a unified exposition of a variety of fusion methods that have been developed so far in different formalisms. Furthermore, the cleaner formulation makes it possible to argue about some delicate issues on a firm mathematical basis. We demonstrate that algebraic fusion and improvement in the world of CPOs and continuous functions can correctly fuse functions that operate on partial and infinite data structures. We also show that subtle differences in termination behaviors of transformed programs caused by certain different fusion methods can be cleanly explained by corresponding improvement processes that have different underlying monoid structures.

### Citations

605 | A transformation system for developing recursive programs
- Burstall, Darlington
- 1977
(Show Context)
Citation Context ...in the following equations: rev (Rev []) = rev [−] = id rev (Rev (a :: l)) = rev (Rev l · (a :: [−])) = (rev (Rev l)) ◦ (rev (a :: [−])) = (rev (Rev l)) ◦ (λwx.w (a :: x)) By folding (in the sense of =-=[2]-=-) the function calls of the form rev(Rev −) , we obtain a recursive function revrev: revrev ∈ Tlist → (Tlist → Tlist) → (Tlist → Tlist) revrev [] w = w revrev (a :: l) w = revrev l (λx.w (a :: x)). Th... |

424 | Deforestation: Transforming programs to eliminate trees
- Wadler
- 1990
(Show Context)
Citation Context ...e is another stream of developments of fusion techniques, based on Burstall and Darlington’s unfold-fold transformation [2]. This line of research was initiated by Wadler, who presented deforestation =-=[22]-=- as a fusion transformation for a particular class of list processing programs. It has been recognized that it is difficult to control the deforestation process, when it is applied to functions with a... |

339 | Theorems for free
- Wadler
- 1989
(Show Context)
Citation Context ... shortcut fusion for tree-terms using the combinator build ′ : (∀α.(α → α → α) → α → α → α) → tree → tree defined by build ′ x y = x tree N L y. As an application of Reynolds’ parametricity principle =-=[14, 21]-=-, we have cata τ k z (build ′ x h) = g τ k z (cata τ k z h). From this, we obtain build’/cata fusion: for any producer prod : ρ → tree → tree and consumer cons : tree → τ satisfying (B-prod) ∃g.prod =... |

202 | A short cut to deforestation
- Gill, Launchbury, et al.
- 1993
(Show Context)
Citation Context ... to implement, as the applicability of the laws can be judged locally without a global analysis of programs. Examples of such calculational methods include the promotion theorem [15], shortcut fusion =-=[9]-=- and its derivatives [8, 19, 11, 6]. These techniques, however, do not give a satisfactory result when applied to functions with an extra argument, called accumulating parameter, on which temporary da... |

194 |
Initial algebra semantics and continuous algebras
- Goguen, Thatcher, et al.
- 1977
(Show Context)
Citation Context ...) and continuous functions. For CPOs D, E, by [D → E] (resp. [D →⊥ E]) we mean the CPO of (resp. strict) continuous functions. The concept of continuous Σ-algebras is fairly standard; see for example =-=[10]-=-. Definition 5.1 A continuous Σ-algebra D is a pair (D, d) of a CPO D and an operator-indexed family of continuous functions {do}o∈Σ such that do ∈ [D n → D] for each o ∈ Σ (n) . A (resp. strict) cont... |

169 |
Traced monoidal categories
- Joyal, Street, et al.
- 1996
(Show Context)
Citation Context ...of boxes in Figure 3 is exactly the pattern which appeared in the definition of the composition of morphisms in Abramsky’s geometry-of-interaction construction [1] and Joyal et al.’s Int-construction =-=[12]-=-.sβ. Since β is a strict monoid homomorphism, the following theorem is an immediate consequence of Proposition 5.2. Theorem 5.7 Let f ∈ [T ∞ Σ →⊥ [[D → D] → [D → D]]] be a result of an algebraic fusio... |

114 | A fold for all seasons
- Sheard, Fegaras
(Show Context)
Citation Context ... blex ′ satisfies blex t = β (blex ′ t) 6. Related Work = λwx.letrec (p, q) = blex ′ t (x, w p) in q. In an early study of fusion laws, Sheard and Fegaras presented the second-order promotion theorem =-=[18]-=-. They demonstrated that the identity function can be obtained from the composition of the list reverse function with itself by applying their fusion law and what they call “inverse” transformation. T... |

111 | H.: Macro Tree Transducers - Engelfriet, Vogler - 1985 |

93 | Shortcut deforestation in calculational form
- Takano, Meijer
- 1995
(Show Context)
Citation Context ...plicability of the laws can be judged locally without a global analysis of programs. Examples of such calculational methods include the promotion theorem [15], shortcut fusion [9] and its derivatives =-=[8, 19, 11, 6]-=-. These techniques, however, do not give a satisfactory result when applied to functions with an extra argument, called accumulating parameter, on which temporary data is accumulated during recursion.... |

70 |
H.: Syntax-Directed Semantics: Formal Models Based on Tree Transducers
- Fülöp, Vogler
- 1998
(Show Context)
Citation Context ...der has proposed the lazy composition technique [20] that solves the issue by an elegant use of circular let. His techniqueswas derived from the corresponding technique developed for tree transducers =-=[4]-=-, which are a close cousin of the attribute grammar formalism. However, he has only informally discussed the correctness of his method resorting to an intuitive account of the laziness. It may be valu... |

67 | Retracing some paths in process algebra, in
- Abramsky
- 1996
(Show Context)
Citation Context ...esting to point out that the connection of boxes in Figure 3 is exactly the pattern which appeared in the definition of the composition of morphisms in Abramsky’s geometry-of-interaction construction =-=[1]-=- and Joyal et al.’s Int-construction [12].sβ. Since β is a strict monoid homomorphism, the following theorem is an immediate consequence of Proposition 5.2. Theorem 5.7 Let f ∈ [T ∞ Σ →⊥ [[D → D] → [D... |

67 | Cheap Deforestation for Non-strict Functional Languages
- Gill
- 1996
(Show Context)
Citation Context ...plicability of the laws can be judged locally without a global analysis of programs. Examples of such calculational methods include the promotion theorem [15], shortcut fusion [9] and its derivatives =-=[8, 19, 11, 6]-=-. These techniques, however, do not give a satisfactory result when applied to functions with an extra argument, called accumulating parameter, on which temporary data is accumulated during recursion.... |

54 |
Attribute coupled grammars
- Ganzinger, Giegerich
- 1984
(Show Context)
Citation Context ... rather simple monoid homomorphism. The second author, Nishimura, proposed a powerful fusion method [16, 17], whose transformation principle was originally drawn from a technique of attribute grammar =-=[5]-=-. His fusion method, however, crucially relies on a transformation called higherorder removal, whose transformation rules have a broken locality. This adds an extra complexity and makes it difficult t... |

54 | Types, abstraction, and parametric polymorphism, part 2
- Ma, Reynolds
- 1992
(Show Context)
Citation Context ... shortcut fusion for tree-terms using the combinator build ′ : (∀α.(α → α → α) → α → α → α) → tree → tree defined by build ′ x y = x tree N L y. As an application of Reynolds’ parametricity principle =-=[14, 21]-=-, we have cata τ k z (build ′ x h) = g τ k z (cata τ k z h). From this, we obtain build’/cata fusion: for any producer prod : ρ → tree → tree and consumer cons : tree → τ satisfying (B-prod) ∃g.prod =... |

50 | Composition and evaluation of attribute coupled grammars - Giegerich - 1988 |

43 | Shortcut fusion for accumulating parameters & zip-like functions - Svenningsson - 2002 |

39 |
Safe Fusion of Functional Expressions II: Further Improvements
- Chin
- 1994
(Show Context)
Citation Context ...cognized that it is difficult to control the deforestation process, when it is applied to functions with accumulating parameters, because some obstructing function calls may incur infinite unfoldings =-=[3]-=-. Voigtländer has proposed the lazy composition technique [20] that solves the issue by an elegant use of circular let. His techniqueswas derived from the corresponding technique developed for tree tr... |

36 |
Homomorphisms and promotability
- Malcolm
- 1989
(Show Context)
Citation Context ...nal methods are easier to implement, as the applicability of the laws can be judged locally without a global analysis of programs. Examples of such calculational methods include the promotion theorem =-=[15]-=-, shortcut fusion [9] and its derivatives [8, 19, 11, 6]. These techniques, however, do not give a satisfactory result when applied to functions with an extra argument, called accumulating parameter, ... |

32 | Benefits of tree transducers for optimizing functional programs - Kühnemann - 1530 |

21 | Composition of functions with accumulating parameters - Voigtländer, Kühnemann - 2004 |

17 |
A generalization of short-cut fusion and its correctness proof
- Johann
(Show Context)
Citation Context ...plicability of the laws can be judged locally without a global analysis of programs. Examples of such calculational methods include the promotion theorem [15], shortcut fusion [9] and its derivatives =-=[8, 19, 11, 6]-=-. These techniques, however, do not give a satisfactory result when applied to functions with an extra argument, called accumulating parameter, on which temporary data is accumulated during recursion.... |

16 | Monadic augment and generalised short cut fusion
- Ghani, Johann, et al.
- 2005
(Show Context)
Citation Context |

16 | Using circular programs to deforest in accumulating parameters
- Voigtländer
- 2004
(Show Context)
Citation Context ...e fusion methods that generate firstorder programs when they are applied to functions with an accumulating parameter, including fusion law for the dmap combinator [13], the lazy composition technique =-=[20]-=-, and a higher-order removal method applied to the result of shortcut fusion [17]. In this paper, we propose a new fusion technique called algebraic fusion. The merits of algebraic fusion over these e... |

7 | Lightweight fusion by fixed point promotion - Ohori, Sasano - 2007 |

7 | Formal efficiency analysis for tree transducer composition - Voigtländer |

5 | On deforesting parameters of accumulating maps
- Kakehi, Gluck, et al.
- 2001
(Show Context)
Citation Context ...lopments have seen several alternative fusion methods that generate firstorder programs when they are applied to functions with an accumulating parameter, including fusion law for the dmap combinator =-=[13]-=-, the lazy composition technique [20], and a higher-order removal method applied to the result of shortcut fusion [17]. In this paper, we propose a new fusion technique called algebraic fusion. The me... |

5 |
Fusion with stacks and accumulating parameters
- Nishimura
- 2004
(Show Context)
Citation Context ...ions with an accumulating parameter, including fusion law for the dmap combinator [13], the lazy composition technique [20], and a higher-order removal method applied to the result of shortcut fusion =-=[17]-=-. In this paper, we propose a new fusion technique called algebraic fusion. The merits of algebraic fusion over these existing methods are addressed below.s• Algebraic fusion is based on the theory of... |

3 |
V.: Generalizing the augment combinator
- Ghani, Uustalu, et al.
- 2006
(Show Context)
Citation Context ... algebraic data types [11] and proved its correctness. Ghani et al. analyzed the underlying mathematical structure of the augment combinator, and proposed a more general scheme called monadic augment =-=[7, 6]-=-. The present paper offers an alternative solution in an algebraic setting, where the elementary theory of monoids and universal algebra give a principled way of devising fusion laws. Built on differe... |

3 |
Correctness of a higher-order removal transformation through a relational reasoning. Pages 358–375 of: Programming language and systems
- Nishimura
- 2003
(Show Context)
Citation Context ...usion (hence, shortcut fusion) yields a higher-order function. This is the motivation for introducing the concept of improvement in Section 4. This problem has already been recognized by Nishimura in =-=[16, 17]-=-, and he introduced a program transformation technique called higher-order removal to reduce the order of computation. His transformation process is designed for a call-by-name language, and it takes ... |

2 | A logic for parametric polymorphism. Pages 361–375 of: International conference on typed lambda calculi and applications - Plotkin, Abadi - 1993 |

1 | Retracting some paths in process algebra. Pages 1–17 of - Abramsky - 1996 |

1 | Attribute coupled grammars. Pages 157– 170 of - Ganzinger, Giegerich - 1984 |

1 | Generalizing the augment combinator. Pages 65–78 of: Trends in functional programming 5. Intellect - Ghani, Uustalu, et al. - 2006 |

1 | A short cut to deforestation. Pages 223–232 of - Gill, Launchbury, et al. - 1993 |

1 | Calculating accumulations. New generation comput - Hu, Iwasaki, et al. - 1999 |

1 | Traced monoidal categories. Mathematical proceedings of the cambridge philosophical society - Joyal, Street, et al. - 1996 |

1 | On deforesting parameters of accumulating maps. Pages 46–56 of: Logic based program synthesis and transformation - Kakehi, Glück, et al. - 2001 |

1 | Homomorphisms and promotability. Pages 335–347 of: Mathematics of program construction - Malcolm - 1989 |

1 | Fusion with stacks and accumulating parameters. Pages 101–112 of - Nishimura - 2004 |

1 | A fold for all seasons. Pages 233–242 of: International conference on functional programming languages and computer architecture (FPCA’93 - Sheard, Fegaras - 1993 |

1 | Shortcut deforestation in calculational form. Pages 306– 313 of: Proc. of international conference on functional programming languages and computer architecture (FPCA’95 - Takano, Meijer - 1995 |

1 | Theorems for free! Pages 347–359 of: International conference on functional programming and computer architecture (FPCA’89 - Wadler - 1989 |