|
RE: Problems with Template Haskell: msg#00004lang.haskell.glasgow.bugs
I'd be interested to know what others think. A big story for Template Haskell is that many type errors are found when you *define* the macro (= template function) rather than when you *call* the macro. In TestSplice2 you had x = $(if False then [d| foo = bar |] else [d| d = 2 |] ) This is rather artificial example; typically the condition will be computed. If TH didn't complain about the absence of 'bar', you might well get an error when you splice x, maybe months later. Still, in your cpp-like application, I guess your story is that the condition might evaluate to True only if the system configuration was such that bar was in scope. If the condition evaluates to False, then bar really might not be available. OK, in TH (version 2 -- CVS HEAD) you want dynamic binding. You can say $(if ... then [|d foo = $(dyn "bar") |] .. ) Now you won't get any type complaint, and "bar" will get looked up at the splice site of x. (see http://research.microsoft.com/~simonpj/tmp/notes2.ps) Does that help? Simon | -----Original Message----- | From: George Russell [mailto:ger@xxxxxx] | Sent: 04 December 2003 11:42 | To: glasgow-haskell-bugs@xxxxxxxxxxx | Cc: Simon Peyton-Jones | Subject: Problems with Template Haskell | | Template Haskell seems to be type-checking some quasi-quotes, even when they | are not going to be used. This is of course a terrible nuisance, since it | means it can't be used to work around interface incompatibilities between | libraries for different versions of GHC (such as the recent change in | RegexString.matchRegexAll's type). Maybe I will have to go back to using | cpp ... | | For example, the attached file fails to compile. | | | # ghc TestSplice.hs -c -fglasgow-exts | > | > TestSplice.hs:7: | > Couldn't match `f a' against `Bool' | > Expected type: f a | > Inferred type: Bool | > In the second argument of `fmap', namely `True' | > In the definition of `TestSplice.p': TestSplice.p = fmap id True | | This occurs for both ghc 6.0.1 and the recent snapshot 6.3.20031201 | | | | Another problem is that Template Haskell objects to undefined variables in | unused splices. Thus if I replace "p = fmap id True" in the | attached file by "foo = bar", I get "TestSplice2.hs:7: Variable not in scope: `bar'" |
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Problems with Template Haskell, George Russell |
|---|---|
| Next by Date: | Re: Problems with Template Haskell, George Russell |
| Previous by Thread: | Problems with Template Haskell, George Russell |
| Next by Thread: | Re: Problems with Template Haskell, George Russell |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |