2

I was under the impression that using functions of type :: Name -> Q [Dec] had to be wrapped in a splice with the TemplateHaskell extension turned on, as e.g. documented in aeson:

$(deriveJSON defaultOptions ''(,,,))

But I just noticed the lens docs show using these TH functions without a splice (or TemplateHaskell), and I just tried it in a library I'm working on and it seems to work fine, even with something like this at the top level:

fmap concat $ forM [''X , ''Y , ''Z ] deriveFoo

Yet after making those modifications (removing from splice and removing pragma), I'm getting this error, unless I put a extensions: TemplateHaskell line in the test-suite block, which I don't really understand.

So is the splice thing a myth? And if so, then why do I need TemplateHaskell in an extensions list for the test-suite?

jberryman
  • 16,334
  • 5
  • 42
  • 83
  • Are you confusing the ' and '' suffixes in the Lens docs for ' and '' prefixes used in templatehaskell? The former is template haskell syntax to refer to the name objects of the variable. The latter is just a valid character for a variable name (ie- x', or "x prime" is just a new variable distinct from x). I have used template haskell in lens, but always with a splice (I certainly don't know every nook and crany though, so I might be missing something). – jamshidh Dec 22 '13 at 18:49
  • @jamshidh no, see the example of `makeLenses` usage at the very top of the lens docs I linked to – jberryman Dec 22 '13 at 18:55
  • 5
    The `$(..)` syntax is optional for top-level splices. It's still Template Haskell (even if the lens docs do not explicitly state this), so you need to enable the extension one way or another. – raymonad Dec 22 '13 at 18:57
  • @raymonad that makes sense, I guess the vagaries of cabal were misleading me there. If you want to make that an answer (and even better: link to the docs), I'll accept it. – jberryman Dec 22 '13 at 19:03
  • 3
    I really wish the splice syntax hadn't been made optional at the top level. It only confuses people without making anything easier. – Carl Dec 22 '13 at 19:15

0 Answers0