Skip to content

Instantly share code, notes, and snippets.

@joelburget
Created June 6, 2017 21:35
Show Gist options
  • Save joelburget/6ffffb44c31884561b74a0e2dd1c1a86 to your computer and use it in GitHub Desktop.
Save joelburget/6ffffb44c31884561b74a0e2dd1c1a86 to your computer and use it in GitHub Desktop.
-- decls :: [Decl]
-- makeTables :: [Decl] -> Tables
quoteDeclarations :: String -> ExpQ
quoteDeclarations str = do
loc <- TH.location
Right decls <- pure $ runTokenParse parseDecls str
-- Antiquotation: must run before `makeTables`
let decls' = dataToExpQ (const Nothing `extQ` replaceVars) decls
-- problem here:
-- • GHC stage restriction:
-- ‘decls'’ is used in a top-level splice, quasi-quote, or annotation,
-- and must be imported, not defined locally
-- • In the untyped splice: $decls'
let tables = makeTables $(decls')
dataToExpQ
(const Nothing `extQ` handleByteString `extQ` handleText)
tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment