[Template-haskell] Representation of unboxed primitives in TH

Sean Seefried sseefried@cse.unsw.EDU.AU
Sat, 19 Apr 2003 23:38:11 +1000 (EST)


I am writing some code in Template Haskell which I hope to use to
transform code.  One thing I want to do is replace integers and Rationals
with their unboxed equivalents. However, Template Haskell doesn't support
this. The relevant error message, triggered by the following expression:

$([| 20# |])

is:

DsMeta.repLiteral: trying to represent exotic literal

I naively tried to add support for the representation of unboxed types by
adding the following clauses to repLiteral

HsIntPrim _  -> intPrimLName
		 HsFloatPrim _ -> floatPrimLName
		 HsDoublePrim _ -> doublePrimLName

I then added the relevant *IdKey and *Name definitions and added the
following constructors to the Lit type in THSyntax.hs

IntPrim, FloatPrim, DoublePrim.

I had a feeling this wouldn't work.  I mean, they're obviously "exotic"
and my suspicion was confirmed when I got segmentation faults compiling
the code.

main = putStrLn (show $([| I# 20# |]))

My question then is, why are they hard to represent? What is it that I am
missing?

Sean Seefried