Quoting functions in Template Haskell

September 7, 2015

While working on this patch, I learned a cool feature of Template Haskell called quoting function. Instead of using VarE (mkName "show") to create an Exp type, you can safely create the same using this: VarE 'Prelude.show. When generating declartions using splicing, the import of the module will be taken care of by itself. A self contained example:

And the other module:

Now you can see this in ghci:

See how I didn’t have to import Data.Time in the Other.hs file. The single quote can be also used for data constructors. Similarly, a type can be converted to Name using double quote.