简体   繁体   中英

Template Haskell: reify in GHCi

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.

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 []] [])"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM