[Haskell] refactoring, catamorphism, termination of programs