[Template-haskell] Couple of Template Haskell Questions

Simon Peyton-Jones simonpj at microsoft.com
Mon Jun 4 05:53:48 EDT 2007


| The first is, how to add generated top level declarations to the export
| list (and how to augment the import list too possibly). Paragraph 7 of
| the second paper seems to acknowledge the problem and suggests a
| solution, but also says it's not implemented (as of Nov. 2003).
| Has this been implemented?

Adding exports: there should be a way to splice in new export declarations, but there isn't at the moment.  Part of the reason is that Haskell doesn't have free-standing export decls; they are all collected at the top.  But TH could have such a thing.

Adding imports: this is generally not necessary, because you can refer to something without importing it, by giving its "original name".  See the Name type in Language.Haskell.TH.Syntax.  My guess is that this'll be enough for you.

However, it *can* make sense to want to add an import decl when you want to get a kind of dynamic-binding effect. Again, that's not implemented at the moment.

| The second is, how to get Haddock to properly document the resulting
| module?

Good question.  At the moment I believe that even the GHC-integrated Haddock works on *pre* typechecked code, but TH expands code during type checking.  So to get Haddock-docs for *post* typechecked code one would need Haddock to run after typechecking.  Also you'll probably want TH to generate TH documentation blobs for Haddock to interpret, which would mean extending TH syntax.

Lots of fun to be had here.  I'm not sure of all the implications.

| Also, the old TH web page says something about not being able
| to splice types. Does that mean no type sigs for generated top
| level declarations?

No, that's not what it means.  I _think_ you can splice top-level type sigs.  What you can't do is say

        f :: Int -> $(foogle 3)

where (foogle 3) expands to a type.

Simon


More information about the template-haskell mailing list