Normally, when using Template Haskell, names of bindings and data constructors are quoted by prefixing them with a single quote:
showName, justName :: Name
showName = 'show
justName = 'Just
Unfortunately, this doesn't work for names whose second character is a single quote, because two single quotes with a single character between them are interpreted as a character literal. How can I work around this?
Edit: It seems the user's guide is wrong about there not being an escape mechanism! You can just add a space after the initial single quote. So... don't use the below hack.
It's possible to work around this limitation using expression quoting and a bogus
Quoteinstance.Now you can write, for example,
How does this work? An expression quote will produce an
Expin an arbitrary monad implementingQuote. In general, desugaring expression quotes may require thenewNamemethod, to desugar things likelets and lambda expressions. However, it does not neednewNameto desugar a plain old binding or data constructor. So we can write a bogusQuoteimplementation for anIdentity-like type that will work for the sorts of quoted expressions we need. Once we've unwrapped the expression, we can extract the name from it.