Template Haskell code for more generic Mendler-style coding