Template Haskell is capable of reifying information about types and
terms defined in previous declaration groups. Top-level declaration
splices break up declaration groups.
For an example, consider this code block. We define a datatype
X and then try to call
reify on the datatype.
module Check where
data X = X
deriving Eq
$(do
info <- reify ''X
runIO $ print info
)
This code fails to compile, noting that
X is not available
for reification at the site of
reify. We can fix this by
creating a new declaration group using an empty top-level splice:
data X = X
deriving Eq
$(pure [])
$(do
info <- reify ''X
runIO $ print info
)
We provide
newDeclarationGroup as a means of documenting this
behavior and providing a name for the pattern.
Since top level splices infer the presence of the
$( ... )
brackets, we can also write:
data X = X
deriving Eq
newDeclarationGroup
$(do
info <- reify ''X
runIO $ print info
)