Re: declaration splicing
Lemmih <[email protected]> Sun, 13 Mar 2005 18:46:38 +0100
| Newsgroups | gmane.comp.lang.haskell.template |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 14 Mar 2005 01:38:25 +0800 (GMT-8), WANG Meng <[email protected]> wrote: > > > >From http://www.haskell.org/ghc/docs/6.4/html/users_guide/template-haskell.html: > > 'Note that the syntax for a declaration splice uses "$" not "splice" > > as in the paper. Also the type of the enclosed expression must be Q > > [Dec], not [Q Dec] as in the paper.' > > Thank you for your reply. I also tried to use "$". But GHC gives > > *Main> $(myparseDec "x=1") > > <interactive>:1: > Couldn't match `Exp' against `Dec' > Expected type: ExpQ > Inferred type: Q Dec > In the application `myparseDec "x=1"' > In the definition of `it': it = $[splice](myparseDec "x=1") > > It seems "$" only takes in an "Q Exp". You can't splice top level declarations from the interactive prompt. Save the code in a file and all will be well. (Notice that the TH code can't be in the module where the splicing takes place, and that your function should have the type 'Q [Dec]' instead of 'Q Dec'.) -- Friendly, Lemmih