Recursion patterns and time-analysis

Manuel Barbosa, Alcino Cunha, Jorge Sousa Pinto
2005 SIGPLAN notices  
This paper explores some ideas concerning the time-analysis of functional programs defined by instantiating typical recursion patterns such as folds, unfolds, and hylomorphisms. The concepts in this paper are illustrated through a rich set of examples in the Haskell programming language. We concentrate on unfolds and folds (also known as anamorphisms and catamorphisms respectively) of recursively defined types, as well as the more general hylomorphism pattern. For the latter, we use as
more » ... ies two famous sorting algorithms, mergesort and quicksort. Even though time analysis is not compositional, we argue that splitting functions to expose the explicit construction of the recursion tree and its later consumption helps with this analysis. Recursion Patterns in a Nutshell Folds. A classic example of a situation where a recursive pattern can be used is given by any function that iterates an arithmetic operator over a list of numbers. Functions such as these, where the result for the recursive case is given as a function of the head of the list and the result of applying recursively the function to the tail, are called folds over lists, and can be written alternatively using the standard Haskell function foldr, defined as:
doi:10.1145/1071221.1071226 fatcat:mv2nsbs26vfzlfo64twvvoqx5a