TemplateHaskell: Allow `Type` splices in `type` and `data` declarations
This is a spin-off of #24922 with a different resolve. Consider
{-# LANGUAGE TemplateHaskell #-}
module Lib where
type $([t| Syn a |]) = Int
data $([t| List a |]) = $([t| Cons a (List a) |]) | $([t| Nil |])
I think we should allow these splices. The parser even accepts types in the corresponding positions; it's just that GHC.Parser.PostProcess.{checkTyClHdr,tyToDataConBuilder}
reject splices in these positions.
The underlying issue is a bit more complex, though: We cannot do name resolution unless we expand the splices first. Thus, these declarations would need to have a similar effect on name resolution as top-level declaration splices such as
-- f :: T -> Int -- invalid! T not visible
-- f x = x
$([d| type T = Int |])
f2 :: T -> Int -- OK
f2 x = x
In this way, this issue relates to the stage restriction #1800. It also relates to #15298 which wants to splice patterns into definition LHS as well.
Edited by Sebastian Graf