Skip to content

Template haskell API makes inconsistent use of [Q Dec], Q [Dec] and Q Dec

Template haskell declaration quotations produce Q [Dec]. However, all of the functions for consuming lists of declarations in Language.Haskell.TH accept only [Q Dec]. This results in some pretty awkward constructs, such as:

instanceD ctxt inst =<< (fmap.fmap) return [d|
  foo a = a * 42
  |]

[Note also that |] must be indented in the above example (otherwise GHC gives an unhelpful error).]

Equally problematically, the functions which /create/ declarations all produce Q Dec, but declaration splices want Q [Dec], resulting in the need to write ugly code or drop into a do-block.

My modest proposal to fix all this is to have only a single type used for declarations within the world of TH. The obvious most-general choice for this type is Q [Dec]. So:[[br]]

  1. Change all [DecQ] arguments to Q [Dec][[br]]
  2. Change all DecQ return types to Q [Dec][[br]]
  3. Add "<++> = liftM2 (++)" for easy combining of Q [Dec] to Language.Haskell.TH.
Trac metadata
Trac field Value
Version 6.12.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information