
I'm goofing with TH and I have my program mostly done: http://hpaste.org/10713 If I have the "$(deriveBinary ''MyData)" line commented out it prints out what looks to me like correct code. I can even paste it into a program and it compiles. However, when the line isn't commented out I get an error I don't understand: test.hs:1:0: Illegal data constructor name: `x' When splicing generated code into the program There are two places in my code I use "x" in splices that could be causing the problem: g <- [| getWord8 >>= \x -> $(caseE [| x |] gcases') |] and put x = $(caseE [| x |] (map return ps)) |] but I don't understand why these might be causing errors (if they are indeed the cause). Using -ddump-splices doesn't help since it seems to hit the error before dumping splices. What's going on here? Tim Newsham http://www.thenewsh.com/~newsham/

Tim Newsham wrote:
I'm goofing with TH and I have my program mostly done:
If I have the "$(deriveBinary ''MyData)" line commented out it prints out what looks to me like correct code. I can even paste it into a program and it compiles.
Pasting the text output can miss errors in the underlying AST, which seems to be what's happening here. If you examine the AST that's produced by: putStrLn $(deriveBinary ''MyData >>= lift . show) ...you can search for occurrences of "x_" and see how they're being constructed. The erroneous ones in this case are of the form: (ConE x_NNNN) ...which explains the error message, "Illegal data constructor name", because this is trying to reference a variable as though it were a constructor. I assume the ConE should really be a VarE. The fix to the program is obvious but I'll leave that as an exercise just in case it's not. :) Anton

Hi Tim, You seem to be duplicating the functionality of Data.Derive to some extent: http://www.cs.york.ac.uk/~ndm/derive/ You might find it easier to use that tool, and if it doesn't meet your needs send in a patch :-) Thanks Neil
-----Original Message----- From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Tim Newsham Sent: 27 September 2008 3:34 am To: haskell-cafe@haskell.org Subject: [Haskell-cafe] TH error
I'm goofing with TH and I have my program mostly done:
If I have the "$(deriveBinary ''MyData)" line commented out it prints out what looks to me like correct code. I can even paste it into a program and it compiles. However, when the line isn't commented out I get an error I don't understand:
test.hs:1:0: Illegal data constructor name: `x' When splicing generated code into the program
There are two places in my code I use "x" in splices that could be causing the problem:
g <- [| getWord8 >>= \x -> $(caseE [| x |] gcases') |] and put x = $(caseE [| x |] (map return ps)) |]
but I don't understand why these might be causing errors (if they are indeed the cause). Using -ddump-splices doesn't help since it seems to hit the error before dumping splices.
What's going on here?
Tim Newsham http://www.thenewsh.com/~newsham/ _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ==============================================================================
participants (3)
-
Anton van Straaten
-
Mitchell, Neil
-
Tim Newsham