Using monads to fuse recursive programs

We try to combine the ‘syntactic composition of tree transducers’ [FV98, KV01] on the one hand side and ‘short cut fusion’ [GLP93] on the other hand side. Short cut fusion is based on the ‘cata/build-rule’ [Joh01] or ‘acid rain theorem’ [TM95]. Therefore it is necessary to represent the recursive functions as catamorphisms. A catamorphism is a generalization of the well known list-function foldr for arbitrary algebraic datatypes. In terms of category theory a catamorphism is the unique mediating morphism from an initial algebra. We invented a new fusion technique using monads: instead of a catamorphism we use the unique mediating morphism from a free monad. Consider the small Haskell program: