RE: [Template-haskell] Representation of unboxed primitives in TH
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 | | 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 | | _______________________________________________ | template-haskell mailing list | template-haskell@haskell.org | http://www.haskell.org/mailman/listinfo/template-haskell
On Tue, Apr 22, 2003 at 03:55:44PM +0100, Simon Peyton-Jones wrote:
I'm not certain that your fix is right, Ian. You are saying that
(I# 30#)
is represented in THSyntax is
(I# 30)
No, this is *in addition* to having a new sort of Lit etc. The problem seemed to be that dsLit was returning a different sort of value - I forget the details now - for IntPrims to Int and Integers, so I rewrote the literal for just that phase. I'm now wondering if it was making it an Int while I was using it as an Integer. Which brings me to another question - in the HsLit datatype an Int# is stored as an Integer - why not an Int? I've attached the diff which I hope will make it clearer. (The HEAD seems to be broken again so I can't test this, but I *think* I've got everything in).
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.
Well, it's already more than Haskell98, so I didn't think there would be any problem extending it to cover everything. I guess you could argue the other things are being developed in the hope they will go into Haskell 2, though. Programmers are free to return an error if given a non-H98 datastructure, although it is a pity Haskell has no way to allow you to define a function on a subset of a datatype so warnings of unhandled cases would still be useful. Thanks Ian
participants (2)
-
Ian Lynagh -
Simon Peyton-Jones