[Haskell-cafe] TH error

Anton van Straaten anton at appsolutions.com
Sat Sep 27 04:40:35 EDT 2008

Tim Newsham wrote:
> 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.  

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.  :)


More information about the Haskell-Cafe mailing list