[Template-haskell] Representation of unboxed primitives in TH

Ian Lynagh igloo@earth.li
Sat, 19 Apr 2003 19:49:36 +0100


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.

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:

 repLiteral :: HsLit -> DsM (Core M.Lit)
 repLiteral lit
-  = do { lit_expr <- dsLit lit; rep2 lit_name [lit_expr] }
+  = do { lit_expr <- dsLit lit'; rep2 lit_name [lit_expr] }
   where
+    lit' = case lit of
+        HsIntPrim i -> HsInteger i
+        _ -> lit
     lit_name = case lit of
         HsInteger _ -> integerLName
         HsInt     _ -> integerLName
+        HsIntPrim _ -> intPrimLName
         HsChar _    -> charLName
         HsString _  -> stringLName
         HsRat _ _   -> rationalLName

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.


Thanks
Ian