Template Haskell: Crash when using newName
GHC/Template Haskell has problems when newName is used
for generating a name for a label of an algebraic
datatype. The example attached consists of a
compile-time function 'recordLabel', it is invoked like
this
$(recordLabel "foo" [t| Int |])
and should produce something like
data Foo = { fooVal_Unique :: Int }
foo r = fooVal_Unique r
(the reason for defining foo as a separate function is
that there is some more code involved in the real
application).
'recordLabel' generates the name of the datatype and
the name of the toplevel access function (Foo and foo
in the example above) from the string argument given.
But fooVal_Unique should be a new name that does not
match any existing name and so I want to use 'newName'
for generating it.
Actually, there are two different problems when using
newName:
When you do 'newName "foo"' than GHC complains about an
ambiguous occurrence `foo'. When you do something like
'newName "_foo"', GHC crashes. There is a better
explanation of the two problems in the source file
Template.hs I attached to this bug report.
I have tested the bug against the precompiled
development snapshot ghc-6.3.20041116 for Linux. Please
note that I had some problems getting the development
snapshot running, because it seems to use a wrong path
to the assembler and so I needed to pass the path to
the assembler with the -pgma flag. Check the file
compile.sh. However, the bug also occurs with
ghc-6.3.20041116.
The example attached contains the files Template.hs,
Test.hs and compile.sh. Template.hs defines the
function recordLabel, Test.hs calls recordLabel and
compile.sh is a small script for invoking GHC.
Trac metadata
Trac field |
Value |
Version |
None |
Type |
Bug |
TypeOfFailure |
OtherFailure |
Priority |
normal |
Resolution |
ResolvedFixed |
Component |
Template Haskell |
Test case |
|
Differential revisions |
|
BlockedBy |
|
Related |
|
Blocking |
|
CC |
|
Operating system |
|
Architecture |
|