Template Haskell code optimized to gain performance