Type signatures are not implicitly quantified over TH type variables
Consider this simple quasiquoter producing a type variable:
tv :: QuasiQuoter
tv = QuasiQuoter { quoteType = varT . mkName }
If a type variable is introduced elsewhere in a type signature, it is implicitly quantified as normal and the TH name resolves properly:
id' :: a -> [tv|a|]
id' x = x
But if the type variable is not mentioned elsewhere in the type, an error results:
const' :: a -> [tv|b|] -> a
const' x _ = x
Not in scope: type variable ‘b’
One would expect the type variable introduced by the TH splice to be included in the implicit quantification of the type signature.
In fact, there is no way to introduce a new type variable in this context, apart from using Rank(2/N)Types
with an explicit forall
. But this prevents the type variable from being referred to elsewhere in the type, eg:
const'' :: [tv|a|] -> b -> [tv|a|]
const'' x _ = x