[Template-haskell] RE: template-haskell

Simon Peyton-Jones simonpj at microsoft.com
Sun Feb 27 22:01:55 EST 2005


Yes, quoted code is typechecked.  The right way to express the result
would be for the TH implementation to make a data structure (Exp, Decl
etc) representing the *typed* code, and then do_something could look at
those types.  This does come up quite regularly.

So why have I not done it? 

(a) It needs some design work on TH syntax.  It must be able to express
typed code (produced by quotes) and untyped code (produced by the user's
program)

(b) The types are only partly there.  For example
	\x -> $(do_something [| \y -> x |])
Here the (\y->x) doesn't know the full type for x.  Indeed just, x's
type may not be fully worked out by the time do_something runs.  For
example we might have
	\x -> ($(do_something [| \y -> x |]), x::Int)
Eventually we know that x::Int, but perhaps not when we run
do_something.  It depends on the order in which the type checker does
things.

This is a pretty nasty problem because the semantics of TH would then
depend on order of type checking etc.

(c) When type checking a splice, should we ignore types in the TH code,
or respect them?  

And, of course, it's work do to. 


The big one is (b).   A pragmatist would say just go ahead and hack
something up -- if you get type information it'll be accurate, but
there's no guarantee of what you'll get.  But I hate that. 

So that's why I keep postponing it.  Better ideas welcomed.

Simon

| -----Original Message-----
| From: Keean Schupke [mailto:k.schupke at imperial.ac.uk]
| Sent: 23 February 2005 14:16
| To: Simon Peyton-Jones
| Subject: template-haskell
| 
| Had a bit of a chat on the template-haskell list about type checking
| meta quoted code... would it be possible (as I don't think it is
currently
| supported) to get the type of meta-quotes expressions,. like:
| 
| $(do_something [|
|     f a = a + 1 |] )
| 
| such that inside the splice we can access the type info for 'f'.
| 
| I know it is type checked, because if will pick up type errors in the
| meta quotes,
| before macro expansion.
| 
| One way of doing this would be to annotate the meta-quote with the
type
| info like:
| 
| [|
|     f :: Num a => a -> a
|     f a = a + 1
| |]
| 
| In other words if the type sig for 'f' is not given, add it to the
data
| structure returned from
| the meta quotes...
| 
| What do you think? possible? easy/hard?
| 
|     Keean.


More information about the template-haskell mailing list