## Adjoint Folds and Unfolds Or: Scything Through the Thicket of Morphisms

### BibTeX

@MISC{Hinze_adjointfolds,

author = {Ralf Hinze},

title = {Adjoint Folds and Unfolds Or: Scything Through the Thicket of Morphisms},

year = {}

}

### OpenURL

### Abstract

Abstract. Folds and unfolds are at the heart of the algebra of programming. They allow the cognoscenti to derive and manipulate programs rigorously and effectively. Fundamental laws such as fusion codify basic optimisation principles. However, most, if not all, programs require some tweaking to be given the form of an (un-) fold, and thus make them amenable to formal manipulation. In this paper, we remedy the situation by introducing adjoint folds and unfolds. We demonstrate that most programs are already of the required form and thus are directly amenable to manipulation. Central to the development is the categorical notion of an adjunction, which links adjoint (un-) folds to standard (un-) folds. We discuss a number of adjunctions and show that they are directly relevant to programming.

### Citations

228 |
Introduction to Functional Programming using Haskell
- Bird
- 1998
(Show Context)
Citation Context ... ′ Z = S Z fib ′ (S n) = fib n + fib ′ n We leave the details to the reader and only remark that the transposed fold corresponds to the usual linear-time implementation of Fibonacci, called twofib in =-=[2]-=-. □ The diagram below illustrates the double adjunction (+) ⊣ ∆ ⊣ (×). C ≺ + ⊥ ∆ ≻ C × C ≺ ∆ ⊥ × ≻ C Each double adjunction actually gives rise to four different schemes and transformations: two for i... |

99 |
de Moor O., Algebra of Programming
- Bird
- 1997
(Show Context)
Citation Context ...our findings. 5 Related Work Building on the work of Hagino [17], Malcolm [23] and many others, Bird and de Moor gave a comprehensive account of the “Algebra of Programming” in their seminal textbook =-=[3]-=-. While the work was well received and highly appraised in general, it also received some criticism. Poll and Thompson write in an otherwise positive review [33]: The disadvantage is that even simple ... |

99 |
and Order in Algorithms
- Law
- 1992
(Show Context)
Citation Context ... x · ∆in = Ψ x ⇐⇒ x1 · in = Ψ1 〈x1, x2〉 and x2 · in = Ψ2 〈x1, x2〉 . If we instantiate the base function to Ψ x = f · ∆(F (φ x)) for some suitable pair of arrows f , we obtain Fokkinga’s mutomorphisms =-=[10]-=-. Fokkinga observes that paramorphisms can be seen as a special case of mutomorphisms. Haskell example 18. We can use mutual value recursion to fit the definition of factorial, see Example 4, into the... |

84 | Nested datatypes
- Bird, Meertens
- 1998
(Show Context)
Citation Context ...ucc (Perfect (a, a)) instance Functor Perfect where fmap f (Zero a) = Zero (f a) fmap f (Succ p) = Succ (fmap (f × f ) p) (f × g) (a, b) = (f a, g b) . The type Perfect is a so-called nested datatype =-=[4]-=- as the type argument is changed in the recursive call. The constructors represent the height of the tree: a perfect tree of height 0 is a leaf; a perfect tree of height n +1 is a perfect tree of heig... |

76 |
Codifying guarded definitions with recursive schemes
- Giménez
- 1994
(Show Context)
Citation Context ...-terms of x’s argument — recall that the type argument of F marks the recursive components. The naturality condition can be seen as the semantic counterpart of the guarded-by-deconstructors condition =-=[15]-=-. This becomes more visible, if we move the isomorphism in : F (µF) ∼ = µF to the right-hand side: x = Ψ x · in ◦ . Here in ◦ is the deconstructor that guards the recursive calls. Termination is an op... |

49 | The Under-appreciated Unfold
- Gibbons, Jones
- 1998
(Show Context)
Citation Context ... only studied later by Vene and Uustalu [39]. (While initial algebras have been the subject of intensive research, final coalgebras have received less attention — they are certainly under-appreciated =-=[13]-=-.) Fokkinga captured mutually recursive functions by mutomorphisms [10]. He also observed that Malcolm’s zygomorphisms arise as a special case, where one function depends on the other, but not the oth... |

36 | Generalised folds for nested datatypes
- Bird, Paterson
- 1999
(Show Context)
Citation Context ...folds. Like folds, adjoint folds are then the unique solutions of their defining equations and, as to be expected, this dualises to unfolds. I cannot claim originality for the idea: Bird and Paterson =-=[5]-=- used the approach to demonstrate that their generalised folds are uniquely defined. The purpose of the present paper is to show that the idea is more profound and more far-reaching. In a sense, we tu... |

22 | Generic downwards accumulations
- Gibbons
- 2000
(Show Context)
Citation Context ...on to the ‘append-problem’ was proposed by Pardo [31]: he introduces folds with parameters and uses them to implement generic accumulations. His accumulations subsume Gibbons’ downwards accumulations =-=[12]-=-. The discovery of nested datatypes and their expressive power [4, 8, 30] led to a flurry of research. Standard folds on nested datatypes, which are natural transformations by construction, were perce... |

17 | Program calculation properties of continuous algebras
- Fokkinga, Meijer
- 1991
(Show Context)
Citation Context ...kell is not one of them. Since Haskell’s underlying category is Cpo ⊥, the category of complete partial orders and strict continuous functions, initial algebras and final coalgebras actually coincide =-=[16, 11]-=-. By contrast, in Set elements of an inductive type are finite, whereas elements of a co-inductive type are potentially infinite. Operationally, an element of an inductive type is constructed in a fin... |

16 | T.: Iteration and coiteration schemes for higherorder and nested datatypes. Theoretical Computer Science 333(1–2
- Abel, Matthes, et al.
- 2005
(Show Context)
Citation Context ...le folds can be based on difunctors [38]. It remains to be seen whether adjoint folds can also be generalised in this direction. Abel, Matthes and Uustalu extended Mendler-style folds to higher kinds =-=[1]-=-. Among other things, they demonstrate that suitable extensions of Girard’s system F ω retain the strong normalisation property and they show how to transform generalised Mendler-style folds into stan... |

14 |
A generalisation of the trie data structure
- Connelly, Morris
- 1995
(Show Context)
Citation Context ...s folds with parameters and uses them to implement generic accumulations. His accumulations subsume Gibbons’ downwards accumulations [12]. The discovery of nested datatypes and their expressive power =-=[4, 8, 30]-=- led to a flurry of research. Standard folds on nested datatypes, which are natural transformations by construction, were perceived as not being expressive enough. The aforementioned paper by Bird and... |

8 |
About Charity, Yellow Series Report 92/480/18
- Cockett, Fukushima
- 1992
(Show Context)
Citation Context ... actual fixed points of the functor F: we have F (µF) ∼ = µF and F (νF) ∼ = νF. The isomorphisms are witnessed by the arrows in : F (µF) ∼ = µF and out : νF ∼ = F (νF). Some languages such as Charity =-=[7]-=- or Coq [35] allow the user to choose between initial and final solutions — the datatype declarations are flagged as inductive or coinductive. Haskell is not one of them. Since Haskell’s underlying ca... |

5 | Parametric datatype-genericity
- Gibbons, Paterson
- 2009
(Show Context)
Citation Context ...(As an aside, DC is the exponential in Cat.) Now, the base functor underlying Perfect is an endofunctor over a functor category: F P = Λ A . A + P (A × A) . Here we use Λ-notation to define a functor =-=[14]-=-. The second-order functor F sends a functor to a functor. Since its fixed point Perfect = µF lives in a functor category, folds over perfect trees are necessarily natural transformations. The functio... |

3 |
P.J.: Inductive types in constructive languages
- Bruin
- 1995
(Show Context)
Citation Context ...or that guards the recursive calls. The type of Ψ is isomorphic to C(A, F A), the type of F-coalgebras. More generally, let F : D → C, then φ : ∀A B . C(A, F B) ∼ = (∀X : D . D(B, X ) → C(A, F X )) . =-=(6)-=- Again, this is an instance of the Yoneda lemma: now H = C(A, F −) is a covariant functor H : C → Set and ∀H B . H B ∼ = (D(B, −) ˙→ H) . Finally, the functions witnessing the isomorphism are φ f = λ ... |