[Template-haskell] Representation of unboxed primitives in TH

Simon Peyton-Jones simonpj@microsoft.com
Tue, 22 Apr 2003 15:55:44 +0100


I'm not certain that your fix is right, Ian.  You are saying that

	(I# 30#)

is represented in THSyntax is

	(I# 30)

When that is translated back to HsSyn, it'll lack the '#', which in turn
will mean that you'll get an overloaded literal 30, which can't be
instantiated to Int#.  So my guess is that this will fail at the splice
point.  No time to try it -- I'm about to go on holiday for 2 wks.

The question is whether you want to be able to represent unboxed Ints in
THSyntax, which is meant to be "nice and simple".  Perhaps yes, because
you want to get GHC extensions through it; in that case THSyntax.Lit
would need an extra constructor.  But perhaps no, because it's meant to
be simple. The more that gets added to THSyntax, the more any program
analysing THSyntax needs to do.

Simon

| -----Original Message-----
| From: template-haskell-admin@haskell.org
[mailto:template-haskell-admin@haskell.org] On Behalf Of
| Ian Lynagh
| Sent: 19 April 2003 19:50
| To: Sean Seefried
| Cc: template-haskell@haskell.org
|=20
| On Sat, Apr 19, 2003 at 11:38:11PM +1000, Sean Seefried wrote:
| > 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.
|=20
| I've just tried this in my local tree (only done IntPrim) and it was
all
| as you say (assuming you also made the necessary changes to
| hsSyn/Convert.lhs too) but I also needed to change repLiteral in
| deSugar/DsMeta.hs as this bit of diff shows:
|=20
|  repLiteral :: HsLit -> DsM (Core M.Lit)
|  repLiteral lit
| -  =3D do { lit_expr <- dsLit lit; rep2 lit_name [lit_expr] }
| +  =3D do { lit_expr <- dsLit lit'; rep2 lit_name [lit_expr] }
|    where
| +    lit' =3D case lit of
| +        HsIntPrim i -> HsInteger i
| +        _ -> lit
|      lit_name =3D case lit of
|          HsInteger _ -> integerLName
|          HsInt     _ -> integerLName
| +        HsIntPrim _ -> intPrimLName
|          HsChar _    -> charLName
|          HsString _  -> stringLName
|          HsRat _ _   -> rationalLName
|=20
| I haven't looked into this in detail, but I'm sure Simon will jump up
if
| it is the wrong thing to do. I probably won't be committing until the
| HEAD builds.
|=20
|=20
| Thanks
| Ian
|=20
| _______________________________________________
| template-haskell mailing list
| template-haskell@haskell.org
| http://www.haskell.org/mailman/listinfo/template-haskell