reifyDecl problem
Hi, All! In test code given below trying to reifyDecl function or constant declaration couse GHC to panic. Both CVS HEAD and 6.0. Am I mising something in reification of function declarations or is this reakky a bug in GHC? [dima@farside tmp]$ ghc --make -fglasgow-exts Main.hs Chasing modules from: Main.hs Compiling Main ( ./Main.hs, ./Main.o ) ghc-6.1: panic! (the `impossible' happened, GHC version 6.1): dsReify reifyDecl Main.l {- v rcA -} Please report it as a compiler bug to glasgow-haskell-bugs@haskell.org, or http://sourceforge.net/projects/ghc/. [dima@farside tmp]$ ghc-6.0 --make -fglasgow-exts Main.hs Chasing modules from: Main.hs Compiling Main ( Main.hs, ./Main.o ) ghc-6.0: panic! (the `impossible' happened, GHC version 6.0): dsReify reifyDecl Main.l {- v rcz -} Please report it as a compiler bug to glasgow-haskell-bugs@haskell.org, or http://sourceforge.net/projects/ghc/. \begin{code} import IO import Language.Haskell.THSyntax data T = A String | B l = A "kuku" f x = x k = reifyDecl l main :: IO () main = do x <- unQ k putStrLn (show x) \end{code} -- Best regards, Dmitry Malenko +----------------------------------------------------+ Registered Linux user #258004 ALT Linux Team http://www.altlinux.ru +----------------------------------------------------+ Marriage, n.: The evil aye.
On Mon, 21 Jul 2003, Dmitry Malenko wrote:
Hi, All!
In test code given below trying to reifyDecl function or constant declaration couse GHC to panic. Both CVS HEAD and 6.0.
Am I mising something in reification of function declarations or is this reakky a bug in GHC?
reifyDecl can only be applied to a type constructor or a class. You've applied it to an expression. Not a very informative error message nonetheless. Sean
On Tue, 22 Jul 2003 02:10:49 +1000 (EST)
Sean Seefried
On Mon, 21 Jul 2003, Dmitry Malenko wrote:
Hi, All!
In test code given below trying to reifyDecl function or constant declaration couse GHC to panic. Both CVS HEAD and 6.0.
Am I mising something in reification of function declarations or is this reakky a bug in GHC?
reifyDecl can only be applied to a type constructor or a class. You've applied it to an expression. Not a very informative error message nonetheless.
But Section 8.1 of "Template Meta-programming for Haskell" says: "In a similar way, reifyDecl f, gives a data structure that represens the value declaration for f;..." and later "... useful to restrict the use of reifyDecl to type constructors, classes, or variables (e.g. functions) declared at the top level..."
From that I made a conclusion that it is possible to reify function declarations (the most interesting ability of TH to me comparing with C++, for instance). And I still hope :) that it is possible and the error message above is just due to mere bug.
Sean _______________________________________________ template-haskell mailing list template-haskell@haskell.org http://www.haskell.org/mailman/listinfo/template-haskell
-- Best regards, Dmitry Malenko +----------------------------------------------------+ Registered Linux user #258004 ALT Linux Team http://www.altlinux.ru +----------------------------------------------------+
But Section 8.1 of "Template Meta-programming for Haskell" says:
"In a similar way, reifyDecl f, gives a data structure that represens the value declaration for f;..."
and later "... useful to restrict the use of reifyDecl to type constructors, classes, or variables (e.g. functions) declared at the top level..."
From that I made a conclusion that it is possible to reify function declarations (the most interesting ability of TH to me comparing with C++, for instance). And I still hope :) that it is possible and the error message above is just due to mere bug.
This you definitely can't do and oh, how I wish you could. The closest you can get is to define a function as reified code and then splice it. Example: d_fun = [d| fun = <function body> |] And then you include $(d_fun) in another file to splice it in. This way you have the reified code "d_fun" and fun is also in scope. You can then manually write a lookup table of strings map to reified function declarations. Sean
participants (2)
-
Dmitry Malenko -
Sean Seefried