Suppose I define my own annotation type:
{-# LANGUAGE DeriveDataTypeable #-}
module Def where
import Data.Data
data MyAnn = MyAnn Int deriving (Show, Typeable, Data)
and some Template Haskell function to access it:
module TH where
import Def
import Language.Haskell.TH.Syntax
myAnn :: Name -> Q Exp
myAnn name = do
[MyAnn x] <- reifyAnnotations (AnnLookupName name)
lift x
I would now like to use it like this:
{-# LANGUAGE TemplateHaskell #-}
module Client where
import Def
import TH
x :: ()
x = ()
{-# ANN x (MyAnn 42) #-}
y :: Int
y = $(myAnn 'x)
But this fails because the myAnn
invocation in the definition of y
gets an empty list from reifyAnnotations
.
It works if I split Client
like this:
module Client1 where
import Def
x :: ()
x = ()
{-# ANN x (MyAnn 42) #-}
{-# LANGUAGE TemplateHaskell #-}
module Client2 where
import Client1
import TH
y :: Int
y = $(myAnn 'x)
Is there a way to get something like the monolithic Client
module to work?