27

Is it somehow possible to do reify in GHCi?

When I try it using 'runQ' it complains "can not do reify in the IO monad".

>>> runQ (reify ''Bool)
Template Haskell error: Can't do `reify' in the IO monad
*** Exception: user error (Template Haskell failure)

I'm not looking for :t or something, only for a way to quickly check what reify returns without writing it to a file and loading that file into GHCi.

1 Answer 1

31

You just have to run it from a splice instead of using runQ:

> $(stringE . show =<< reify ''Bool)
"TyConI (DataD [] GHC.Types.Bool [] [NormalC GHC.Types.False [],NormalC GHC.Types.True []] [])"
2
  • 6
    You can use putStrLn $(stringE . pprint =<< reify ''Bool) to get pretty-printed output. Commented Aug 16, 2014 at 19:44
  • 5
    Is it possible to actually extract the value into a variable, instead of just converting it to a string?
    – Hjulle
    Commented Jun 3, 2016 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.