[Template-haskell] TH preprocessing

Simon Peyton-Jones simonpj at microsoft.com
Tue May 25 12:33:45 EDT 2004


| I wouldn't mind having a look at this. If you could tell me a little
| about the purpose of the dictionary stuff I'd be willing to have a go
| at adding this feature.

Great!

GHC's type checker generates a *translated program* as well as a *type*.
The translated program has explicit type abstractions and applications
(in the style of System F), as well as explicit dictionary abstractions
and applications.  The latter is part of the "dictionary-passing" or
"evidence-passing" way of implementing type classes, which you can find
described in any paper about type classes.

Rather than attempt a half-baked explanation, you might want to talk to
Don or Manuel, both of whom understand the translation idea.  (At least,
I know Manuel does.)

In Template Haskell, the typechecker also expands splices, so the
translated program has the expanded version.

The idea, then, would be to print out the type-checked program, as
Haskell source that could be stuffed back into GHC right at the front.
The main issues I can think of are these:

1.  The pretty-printer for HsSyn does not print precisely Haskell
syntax.  This should be easy to fix.

2.  To print Haskell source, you need to remove the extra stuff inserted
by the translation.  I suggest
this is a HsSyn->HsSyn pass, to avoid writing a second pretty-printer.  

Many of the translated bits are flagged by special HsSyn constructors
(e.g. DictLam).  I'm not certain that all are.

3.  One particular construct, AbsBinds, is what a binding group is
translated to.  There you will find
dictionary bindings and programmer bindings mixed up together. I think
the former are all VarMonoBinds while the latter never are, so I think
you can disentangle them fine.


I'm happy to help you, but the easiest way to do so is probably to
create a branch in ghc/compiler (only) so that I can see what you've
done and fiddle where necessary.   Manuel knows how to do that.  Make
sure you *tag* the tree just before you *branch* it, so that we can
subsequently merge easily
	cd ghc/compiler
	cvs update
	cvs tag th-print-branch-point
	cvs tag -b th-print-branch

Simon

| -----Original Message-----
| From: template-haskell-bounces at haskell.org
[mailto:template-haskell-bounces at haskell.org] On
| Behalf Of Sean Seefried
| Sent: 21 May 2004 05:30
| To: Template Haskell Mailing List
| Subject: Re: [Template-haskell] TH preprocessing
| 
| 
| On 10/05/2004, at 6:29 PM, Simon Peyton-Jones wrote:
| 
| > Not at present.  It's actually a little trickier than it looks,
because
| > the post-type-checked program (with the splices expanded) has
| > dictionary
| > stuff floating around, and it's not entirely straightforward to
convert
| > it back to vanilla source Haskell.
| > You're right it would be useful.  I think it's feasible with a bit
of
| > work.  I'd be willing to help anyone who wanted to undertake it.
| >
| 
| I wouldn't mind having a look at this. If you could tell me a little
| about the purpose of the dictionary stuff I'd be willing to have a go
| at adding this feature.
| 
| Sean
| 
| _______________________________________________
| template-haskell mailing list
| template-haskell at haskell.org
| http://www.haskell.org/mailman/listinfo/template-haskell


More information about the template-haskell mailing list