I have a function that returns a dynamically-bound Type
- in essence, ConT $ mkName "MyType"
. Of course, the actual function is significantly more complicated, enough so that I'd like to write tests for it, and preferably legible ones. But the following:
import Language.Haskell.TH
import MyTypeModule (MyType)
myFn :: Type
myFn = ConT $ mkName "MyType"
test = ... $ do
m <- runQ [t| MyType |]
myFn `shouldBe` m
Will always fail, since m
will resolve to ConT MyTypeModule.MyType
rather than to ConT MyType
.
Is there a nice way to transform the myFn
type to something fully-qualified, or otherwise check that m
and myFn
are the same (in the current context)?
Wow long time without an answer, but never too late to post answers on the Internet!
myFn = ConT ''MyType
The ticks are enabled with the -XTemplateHaskell
language extension, and are documented here: