## Automatic visualization of recursion trees: a case study on generic programming

Venue: | Electronic Notes in Theoretical Computer Science |

Citations: | 1 - 0 self |

### BibTeX

@INPROCEEDINGS{Cunha_automaticvisualization,

author = {Alcino Cunha},

title = {Automatic visualization of recursion trees: a case study on generic programming},

booktitle = {Electronic Notes in Theoretical Computer Science},

year = {}

}

### OpenURL

### Abstract

Although the principles behind generic programming are already well understood, this style of programming is not widespread and examples of applications are rarely found in the literature. This paper addresses this shortage by presenting a new method, based on generic programming, to automatically visualize recursion trees of functions written in Haskell. Crucial to our solution is the fact that almost any function definition can be automatically factorized into the composition of a fold after an unfold of some intermediate data structure that models its recursion tree. By combining this technique with an existing tool for graphical debugging, and by extensively using Generic Haskell, we achieve a rather concise and elegant solution to this problem. 1

### Citations

303 | Functional programming with bananas, lenses, envelopes and barbed wire
- Meijer, Fokkinga, et al.
- 1991
(Show Context)
Citation Context ...(b -> Maybe (a,b,b)) -> b -> Tree a unfoldT h x = case (h x) of Nothing -> Leaf Just (x,l,r) -> Node x (unfoldT h l) (unfoldT h r) The composition of a fold after an unfold is known as a hylomorphism =-=[17]-=-. Note that since the fixed point operator can be defined as a hylomorphism, this recursion pattern can express any recursive function [18]. For a wide class of function definitions the intermediate d... |

175 | PolyP—a polytypic programming language extension
- Jansson, Jeuring
- 1997
(Show Context)
Citation Context ...ards be re-used for any specific data type. The principles behind generic programming are already well understood [2], and several languages supporting this concept have been developed, such as PolyP =-=[13]-=- or Generic Haskell [3]. Unfortunately, this style of programming is not widespread, and we rarely find in the literature descriptions of applications developed in these languages. This paper addresse... |

122 | Implementing type classes
- Peterson, Jones
- 1993
(Show Context)
Citation Context ...on of the observer function is always the same. In the presence of an extension to the type system allowing for the specification of polymorphic predicates in an instance declaration, as presented in =-=[11]-=-, we could have a single definition that would look like instance (forall b . (Observable b) => Observable (f b)) => Observable (Mu f) where observer (In x) p = In (observer x p) Recently, Valery Trif... |

107 | Polytypic values possess polykinded types
- Hinze
- 2002
(Show Context)
Citation Context ...to implement the map function for each functor. In order to avoid this task we will use Generic Haskell [3]. This language extends Haskell with polytypic features and originates on work by Ralf Hinze =-=[8,9]-=-, where generic functions are defined by induction on the structure of types, by providing equations for the base types and type constructors (like products and sums). Given this information, a generi... |

96 | Bananas in space: extending fold and unfold to exponential types
- Meijer, Hutton
- 1995
(Show Context)
Citation Context ...osition of a fold after an unfold is known as a hylomorphism [17]. Note that since the fixed point operator can be defined as a hylomorphism, this recursion pattern can express any recursive function =-=[18]-=-. For a wide class of function definitions the intermediate data structures correspond to their recursion trees. For example, quick-sort can be easily implemented as a hylomorphism by using a binary s... |

95 | A new approach to generic functional programming
- Hinze
- 1999
(Show Context)
Citation Context ...to implement the map function for each functor. In order to avoid this task we will use Generic Haskell [3]. This language extends Haskell with polytypic features and originates on work by Ralf Hinze =-=[8,9]-=-, where generic functions are defined by induction on the structure of types, by providing equations for the base types and type constructors (like products and sums). Given this information, a generi... |

84 | Generic programming — an introduction
- Backhouse, Jansson, et al.
- 1999
(Show Context)
Citation Context ...by induction on the structure of types. It is defined once and for all, and can afterwards be re-used for any specific data type. The principles behind generic programming are already well understood =-=[2]-=-, and several languages supporting this concept have been developed, such as PolyP [13] or Generic Haskell [3]. Unfortunately, this style of programming is not widespread, and we rarely find in the li... |

58 | Type-indexed data types
- Hinze, Jeuring, et al.
(Show Context)
Citation Context ...bstracted from an expression. Typically this involves applying predefined generic functions to the type variable. For example, our recursion patterns can be defined by generic abstractions as follows =-=[10]-=-. fold {| f :: * -> * |} :: (f b -> b) -> Mu f -> b fold {| f |} g = g . gmap {| f |} (fold {| f |} g) . out unfold {| f :: * -> * |} :: (a -> f a) -> a -> Mu f unfold {| f |} h = In . gmap {| f |} (u... |

55 | Debugging haskell by observing intermediate data structures
- Gill
- 2000
(Show Context)
Citation Context ...information. Note that the generic definitions of the recursion patterns can be used for every new functor F. 6 Observing Recursion Trees GHood [19] is a graphical animation tool built on top of Hood =-=[7]-=- (Haskell Object Observation Debugger). Hood is a portable debugger for full Haskell, based on the observation of intermediate data structures. Essentially, it introduces the following combinator with... |

48 | The Under-Appreciated Unfold
- Gibbons, Jones
- 1998
(Show Context)
Citation Context ...af = g Nothing foldT g (Node x l r) = g (Just (x, foldT g l, foldT g r)) The dual of fold is the unfold or anamorphism. Although already known for a long time it is still not very used by programmers =-=[6]-=-. This recursion pattern encodes a standard way of producing a value of a given data type, and for lists it is defined as unfoldr in one of the standard libraries of Haskell. unfoldr :: (b -> Maybe (a... |

47 | Deriving structural hylomorphisms from recursive definitions
- Hu, Iwasaki, et al.
- 1996
(Show Context)
Citation Context ...that automatically factorizes a recursive definition into the composition of a fold and an unfold of an intermediate data structure. This algorithm was first presented by Hu, Iwasaki, and Takeichi in =-=[12]-=-, where it was applied to program deforestation. A well known side-effect of the factorization is that the intermediate data structure models the recursion tree of the original definition. The visuali... |

32 | The Generic Haskell user’s guide
- Clarke, Hinze, et al.
- 2001
(Show Context)
Citation Context ...specific data type. The principles behind generic programming are already well understood [2], and several languages supporting this concept have been developed, such as PolyP [13] or Generic Haskell =-=[3]-=-. Unfortunately, this style of programming is not widespread, and we rarely find in the literature descriptions of applications developed in these languages. This paper addresses this shortage by pres... |

28 | Sorting morphisms
- Augusteijn
- 1998
(Show Context)
Citation Context ... the intermediate data structures correspond to their recursion trees. For example, quick-sort can be easily implemented as a hylomorphism by using a binary search tree as intermediate data structure =-=[1]-=-. The unfold should build a search tree containing the elements of the input list, and the fold just traverses it inorder. qsort :: (Ord a) => [a] -> [a] qsort = (foldT g) . (unfoldT h) where h [] = N... |

26 |
Monadic Maps and Folds for Arbitrary Datatypes. Memoranda Informatica 94-28
- Fokkinga
- 1994
(Show Context)
Citation Context ...nadic map for ObserverM. Given a functor F , and a monad M, the monadic map should transform functions of type A → M B into functions of type F A → M (F B). This concept was introduced by Fokkinga in =-=[5]-=-. For example, in the standard Prelude of Haskell, the function mapM implements the monadic map for lists. However, likewise to the regular map function, given a polynomial functor the monadic map can... |

8 | Ghood — graphical visualisation and animation of haskell object observations
- Reinke
- 2001
(Show Context)
Citation Context ...de-effect of the factorization is that the intermediate data structure models the recursion tree of the original definition. The visualization of this structure is defined generically on top of GHood =-=[19]-=-, a system to graphically trace Haskell programs. This paper is structured as follows. In section 2 we informally show how the well-known fold and unfold functions on lists can be generalized to arbit... |

3 |
Lexically-scoped type variables. To be submitted to The Journal of Functional Programming
- Jones, Shields
- 2002
(Show Context)
Citation Context ...ure should be a binary tree with elements of type a, defined as the fixed point of FTree a. If Generic Haskell allowed the definition of scoped type variables (an extension to Haskell 98 described in =-=[15]-=-), one could define qsort as follows. qsort :: (Ord a) => [a] -> [a] qsort (l::[a]) = hylo {| FTree a |} g h l where ... Unfortunately, since Generic Haskell does not support this extension we had to ... |

2 | Deriving animations from recursive definitions
- Cunha, Barros, et al.
- 2002
(Show Context)
Citation Context ... been explicitly declared in a recursive fashion. The constructors of the data type are not displayed because their derived names are meaningless. Using these definitions, the recursion tree of qsort =-=[3,2,4,3,1]-=- is visualized as shown on figure 1. Another problem with the previous instances is that they imply the definition of a particular instance for Mu applied to any possible derived functor, even if the ... |

1 |
Re: Type class problem. Message posted on the Haskell mailing list
- Kiselyov
- 2003
(Show Context)
Citation Context ...ral, be simulated in standard Haskell 98 [20]. However, for this par10sCunha Fig. 1. Recursion tree of qsort [3,2,4,3,1]. ticular example we will rely in a simpler solution suggested by Oleg Kiselyov =-=[16]-=-. First, we define a single instance of the Observable class for Mu as instance (Observable (f (Mu f))) => Observable (Mu f) where observer (In x) p = In (observer x p) This implies that, for a partic... |

1 |
Simulating quantified class constrains
- Trifonov
- 2003
(Show Context)
Citation Context ...le (f b)) => Observable (Mu f) where observer (In x) p = In (observer x p) Recently, Valery Trifonov has shown how this type of class constrains could, in general, be simulated in standard Haskell 98 =-=[20]-=-. However, for this par10sCunha Fig. 1. Recursion tree of qsort [3,2,4,3,1]. ticular example we will rely in a simpler solution suggested by Oleg Kiselyov [16]. First, we define a single instance of t... |

1 |
DrIFT User Guide (version 2.0rc3
- Winstanley, Meacham
- 2002
(Show Context)
Citation Context ...al concepts as Generic Haskell, but that only allows generic definitions in instance declarations. Unfortunately, it is not yet fully implemented in any Haskell distribution. An older system is DrIFT =-=[21]-=-, a preprocessor that parses a Haskell module for special commands that trigger the generation of new code. This is a rather ad hoc mechanism, which is not as theoretically sound as generic programmin... |