-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Qualified import of singletons #306
Comments
Unfortunately, no. Template Haskell doesn't give you any way to distinguish between a qualified and non-qualified name, as the following program demonstrates: {-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH
import qualified Prelude
import Prelude
main :: IO ()
main = putStr
$(do ConT nonQualName <- [t| Bool |]
ConT qualName <- [t| Prelude.Bool |]
stringE $ unlines
[ "Non-qualified name " ++ show nonQualName
, "Qualified name " ++ show qualName
, "Are they equal? " ++ show (nonQualName == qualName)
])
Therefore, I can't recall if there's an open GHC ticket about this, but one thing is for sure: this is not possible unless Template Haskell were to be changed so that qualified names would be preserved when quoted. |
Thank you for explanation. |
I don't think it would even be possible with quasiquoting. You'd still have to deal with names like |
Hmm... Maybe it could be done more simple then with QQ? [ValD (VarP bar_1) (NormalB (VarE ModuleFoo.foo)) []] We have to generate other definitions with changing e.g. |
It is true that quoted names do give you the module information, yes. However, this is often not enough to figure out where the singleton definitions are! For instance, if you quote In short, this is a complicated problem that's further complicated by Template Haskell inadequacies, and I don't see a straightforward solution. |
I agree with Ryan's summary above. Even if TH could track such qualifications, making use of them would require the assumption that singleton definitions are in the same module as the original definitions. This is not true all the time. I suppose you could also teach My bottom line: |
I'll opt to close this, as we can't fix this on
The second issue is surmountable if we fixed #204. The first issue, on the other hand, would need to be fixed by adding more functionality to Template Haskell. So perhaps fixing that could be a jumping point into getting back to this issue. |
If I define in one module
singletons [d| foo = ... |]
and import it qualified (as
F
) to another module and useF.foo
in another template:singletons [d| bar = F.foo |]
I get errors like
Not in scope: type constructor or class ‘FooSym0’
If I import
FooSym0
unqualified I also get an errorVariable not in scope: sFoo
Is it possible to use qualified names (
F.FooSym0
,F.sFoo
) for qualified name in template?The text was updated successfully, but these errors were encountered: