Couple of Template Haskell Questions
Hello, I've been considering using this and have read the 2 papers papers about the basic design, but these don't seem to cover a couple of issues that I anticipate as possible "show stoppers" for me. 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? The second is, how to get Haddock to properly document the resulting module? I gather it is possible to get TH to emit another module (as source text), so that may be 1 possible solution to both these problems. I'm not sure how this will interact with --make option and Cabal though. 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? Thanks -- Adrian Hey
Hello Adrian, Saturday, June 2, 2007, 6:19:50 PM, you wrote:
I gather it is possible to get TH to emit another module (as source text), so that may be 1 possible solution to both these problems. I'm not sure how this will interact with --make option and Cabal though.
zeroth? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
| 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
participants (3)
-
Adrian Hey -
Bulat Ziganshin -
Simon Peyton-Jones