Template Haskell crashes unexpectedly...

Arie Peterson ariep at xs4all.nl
Mon Aug 21 11:08:31 EDT 2006


Hello Brian,


> [snip]
>         getInfo :: Q Info
>         getInfo = reify (mkName "Car")
> [snip]
>             -- Crashes if I try to print out the info
>             -- info <- runQ getInfo
>             -- putStrLn (pprint info)
> [snip]
>
> The example from the paper works fine with the few minor adjustements ie
> Expr --> ExpQ, lift --> stringE. However if I try and obtain the Info it
> compiles but then crashes at runtime (using ghc 6.4.2 on Windows).
>
> Any ideas? (Perhaps because the type doesn't exist - yet the first call to
> runQ (printf...) *does* work at runtime)

I seem to remember that 'reify' cannot be run in the IO monad. IIRC ghci
gives a nice error message saying this, so perhaps you can try to execute
'main' from within ghci to corroborate my suspicion.

> Also, I'm puzzled by the type of reify, because the name "Car" above
> should
> surely be both a TyConI and a DataConI so how does this function decide
> which to return the info about? I expected an extra parameter to determine
> what namespace to look the name up in.

The preferred way to refer to names that are in scope is by using the
quotation mechanism:

  'getName    is the name of the function 'getName'
  ''Object    is the name of the type 'Object'

This also makes the distinction you rightly wanted.


Greetings,

Arie

-- 

Mr. Pelican Shit may be Willy.

  ^
 /e\
 ---




More information about the Glasgow-haskell-users mailing list