I'm trying to make a quasiquoter that defines some simple sugar for type declarations. The easiest way to do this is to just use some regular expressions to modify the input text string. But when I compile this code outline code:
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
import Language.Haskell.TH
import Language.Haskell.TH.Quote
myquote = QuasiQuoter
{ quoteDec = \d -> [d| d |]
}
GHC generates an error saying:
Declaration splices are not permitted inside declaration brackets
Why is this not allowed? Is there any way to splice declarations? It seems like the only alternative is reparsing the whole input declaration, which would just be obnoxious.
haskell-src-meta has a parseDecs :: String -> Either String [Dec]
to do that parsing.