What `reify` sees in Template Haskell

Francesco Mazzoli f at mazzo.li
Fri Feb 13 12:53:40 UTC 2015


Hi,

I recently stumbled upon the issue of `reify` not being able to give
information about local variables, as of GHC 7.8.  For example, this
won't work:

    foo x = $(do {xInfo <- reify 'x; ...})

The motivation for this change is described here:
<https://ghc.haskell.org/trac/ghc/wiki/TemplateHaskell/BlogPostChanges#PartC:Reificationandtypechecking>.

While I agree that getting the type of local variables is going to be
brittle, I also think that offering that functionality is extremely
useful in certain cases, such as in the case of the language-c-inline
library, that used this facility to avoid having to type verbose type
annotations -- see
<https://github.com/mchakravarty/language-c-inline/issues/25>.

My two part question is:

  1. would it be possible to revert to the old behavior easily, or is
doing that difficult or impossible now given the overall changes to
the Template Haskell code?
  2. if 1, wouldn't it make more sense to allow reifying all names if
the user really wants, maybe with a specific `unsafeReify` function or
similar?

It should be made clear in the docs that by using `unsafeReify` the
user is relying on GHC internals (specifically the internals of type
checking).

Also, I think that post should at least be referenced in the manual,
for lack of better documentation.  This behavior is not mentioned
anywhere else.

Thanks,
Francesco


More information about the ghc-devs mailing list