2

Lets say I have a custom quasiquote, named xpto:

[xtpo|data Something = Abc | Def deriving (Eq,Ord,Show,Enum,Bounded)|]

I want to actually declare this as it is, but additionally derive some more stuff based on the constructor names. That last part is done (function generateDataDefs, irrelevant here), but I am doing inclusion of the original declaration through haskell-src-meta, which seems like quite an heavy dependency. Like this:

xpto = QuasiQuoter { quoteDec = either (const . return $ []) generateDataDefs
                                                           . parseDecs }

Can I avoid using parseDecs and just use Template Haskell instead?

PS: the function generateDataDefs takes the received [Dec], and appends the new code to it:

generateDataDefs :: [Dec] -> Q [Dec]
generateDataDefs decData = let
(...)
 in return $ decData ++ remainingStuff
jcristovao
  • 554
  • 2
  • 12
  • You could not use a quasiquoter, and have users write `generateDataDefs =<< [d|data Something = Abc | Def deriving (Eq,Ord,Show,Enum,Bounded)|]` instead – aavogt May 30 '14 at 23:31
  • Perfect. Please make that an answer so that I can mark it as correct. Thanks! – jcristovao Jun 04 '14 at 09:23

1 Answers1

2

You could not use a quasiquoter, and have users write

    generateDataDefs =<< [d|data Something = Abc
                                        | Def
                              deriving (Eq,Ord,Show,Enum,Bounded)|]
aavogt
  • 1,308
  • 6
  • 14