1

I'm trying to write a declaration using expression quotation, and whatever I try the compiler fails on pattern with a message like the following:

Parse error in pattern: $pattern

Here's an example:

{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
import Language.Haskell.TH

data A = A Int Int

decl :: DecsQ
decl = [d|
    instance Show A where
      show $pattern = undefined
  |]
  where
    pattern = conP (mkName "A") $ map varP $ map mkName $ ["a", "b"]
Nikita Volkov
  • 42,792
  • 11
  • 94
  • 169

2 Answers2

4

The TH documentation says that:

Note that pattern splices are not supported

More details here

Ankur
  • 33,367
  • 2
  • 46
  • 72
2

GHC HEAD (7.8-to-be) has improved TH support and successfully compiles your code.

sdcvvc
  • 25,343
  • 4
  • 66
  • 102