Nikita Volkov
Nikita Volkov

Reputation: 43310

How to write pattern splices in expression quotation?

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"]

Upvotes: 1

Views: 177

Answers (2)

sdcvvc
sdcvvc

Reputation: 25654

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

Upvotes: 2

Ankur
Ankur

Reputation: 33637

The TH documentation says that:

Note that pattern splices are not supported

More details here

Upvotes: 4

Related Questions