TH d-QuasiQuoter should defer "accompanying binding" checks
I want to write something like:
$(generateExtras
[d| myFunc :: T |]
(\(~[myFunc']) -> [d| myFunc = ... $(myFunc') ... |]))
where generateExtras
generates myFunc'
from the type-signature of myFunc
, and passes it to be used in the RHS of the definition of myFunc
. However the above code causes GHC to complain about "type signature for 'myFunc' lacks an accompanying binding".
OTOH, writing the Q Dec
instance manually works:
$(generateExtras
(pure <$> sigD (mkName "myFunc") [t| Int |])
(\(~[myFunc']) -> [d| myFunc = ... $(myFunc') ... |]))
so it seems reasonable that the [d|..|]
quasi-quoted version should also succeed.
(Actually, as an aside, in case this was a X-Y problem, ideally I'd write something like the following:
$(generateExtras $ \(~[myFunc']) -> [d|
myFunc :: T
myFunc = ... $(myFunc') ...
but even using the MonadFix
instance from #12073 (closed) and being very careful in the implementation of generateExtras
not to pattern-match on the RHS of any non-SigD
declarations, causes an infinite loop during compilation. :()