On 17/09/2003, at 9:07 PM, Simon Peyton-Jones wrote:
| If your 'x' variable is monomorphic, you can use the rType function | that Sean and I came up with, detailed here: | | http://www.haskell.org/pipermail/template-haskell/2003-July/ 000128.html | | That currently handles only 2-tuples, but it shouldn't be too hard to | extend it to work on any-size tuples. Let me know if you're having | problems.
I missed that message. How does rType differ from typeOf, defined in Data.Typeable?
typeOf :: a -> TypeRep rType :: a -> Typ (or :: a -> Type in the new THSyntax definitions). The two are conceptually the same, but they return you different data types: typeOf returns you the TypeRep which the Data.Dynamic functions use, and rType returns you a Typ (now Type) which THSyntax uses. Another way to think about it is that rType is Template Haskell's reifyType as a function. The point is that you can use rType to return you the definition of a Type given in THSyntax, which you can then use directly within THSyntax: *Mocha.ReifyType> Data.Dynamic.typeOf (undefined :: (Int, Char)) (Int,Char) *Mocha.ReifyType> rType (undefined :: (Int, Char)) AppT (AppT (TupleT 2) (ConT "GHC.Base:Int")) (ConT "GHC.Base:Char") *Mocha.ReifyType> Come to think of it, now that we have a concrete syntax, perhaps it'd be worth merging the definitions of THSyntax's Type and Data.Dynamic's TypeRep? They're conceptually the same thing, but with different data representations ... A slightly wilder idea (which is not a serious suggestion) would be to use Template Haskell to implement Dynamics. If there's a pre-defined "Dynamic" data type, all the various toDyn and fromDyn functions could be meta-programmed so that they emit code to convert to and from the Dynamic type. Effectively you could use Template Haskell as a generics/polytopic system. I have no idea whether this is possible, it's just a fleeting thought. BTW, you didn't miss that message Simon -- you even replied[1] to it :). 1. http://www.haskell.org/pipermail/template-haskell/2003-July/000129.html -- % Andre Pang : trust.in.love.to.save