Implemented the memoizing catamorphism.