Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'dumpSplices' #5

Closed
neongreen opened this issue Oct 2, 2017 · 2 comments
Closed

Add 'dumpSplices' #5

neongreen opened this issue Oct 2, 2017 · 2 comments

Comments

@neongreen
Copy link
Contributor

neongreen commented Oct 2, 2017

I often use this utility for debugging TH code or understanding libraries that use TH (persistent, lens, etc):

-- | Print splices generated by a TH splice (the printing will happen
-- during compilation, as a GHC warning). Useful for debugging.
--
-- For instance, you can dump splices generated with 'makeLenses' by
-- replacing a top-level invocation of 'makeLenses' in your code with:
--
-- @dumpSplices $ makeLenses ''Foo@
--
dumpSplices :: DecsQ -> DecsQ
dumpSplices x = do
  ds <- x
  let code = lines (pprint ds)
  reportWarning ("\n" ++ unlines (map ("    " ++) code))
  return ds

However, it doesn't have a home and so I end up copying it from project to project. Perhaps it could be adopted by th-utilities? If so, I'll make a PR.

@neongreen
Copy link
Contributor Author

neongreen commented Oct 2, 2017

(I know about -ddump-splices, of course, but my function lets you dump a specific splice instead of everything in the module, which makes a big difference when you have e.g. dozens of makeLenses in your code. Also, :set -ddump-splices breaks haskell-mode.)

@mgsloan
Copy link
Collaborator

mgsloan commented Oct 2, 2017

Sure, this would be a quite sensible addition to the TH.Utilities module, a PR would be appreciated!

neongreen pushed a commit to neongreen/th-utilities that referenced this issue Oct 2, 2017
@mgsloan mgsloan closed this as completed in #6 Oct 3, 2017
mgsloan pushed a commit that referenced this issue Oct 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants