RE: [Template-haskell] Re: template-haskell names in 6.3
do you mean n <- newName s or let n = mkName s ? If the former, you'll get a new decl like data Foo_24 = Foo_098 Foo_24 which definitely won't clash. We discussed this, and I've implemented it. If the latter, you will get data Foo = Foo Foo ... and then I see what you want. You want a version of mkName that is like giving a qualified name in Haskell. It's dynamically scoped just like mkName, but it obeys the usual rules for qualified names in Haskell. To be totally explicit, suppose I have foo = [| mkQualName "Foo" "baz" |] then if I call foo thus wibble = \baz -> $foo the $foo splice will expand to "Foo.baz", and that won't see the \baz; it'll see whatever Foo.baz is in scope. Is that what you seek? I can see it's reasonable. I'd need to add mkQualName :: String -> String -> Name That'd mean an extra form of Name. Currently, if you say 'Foo.baz you'll get a Name whose nameModule isn't necessarily Foo... it'll be the module that baz was actually defined in. Simon | -----Original Message----- | From: Keean Schupke [mailto:k.schupke@imperial.ac.uk] | Sent: 03 December 2004 13:09 | To: Simon Peyton-Jones | Subject: Re: [Template-haskell] Re: template-haskell names in 6.3 | | Okay, | | makeDecl :: String -> DecQ | makeDecl s = do | n <- mkName s | dataD (cxt []) n [] [normalC n [(NotStrict,ConT n)]] | | $(makeDecl "Foo") | | will give: | | data Foo = Foo Foo | | what I want is: | | makeDecl :: String -> DecQ | makeDecl s = do | n <- mkName s | m <- qCurrentModule | n' <- mkNameG m s | dataD (cxt []) n [] [normalC n [(NotStrict,ConT n')]] | | $(makeDecl "Foo") -- now gives: | | data Foo = Foo Module.Foo | | to disambiguate from OtherModule.Foo | | Keean. | | Simon Peyton-Jones wrote: | | >But you used newName to generate the data type, so you do have the | >name.! | > | >I guess the only way to understand this is for you to give a small TH | >program that demonstrates the problem | > | >| -----Original Message----- | >| From: Keean Schupke [mailto:k.schupke@imperial.ac.uk] | >| Sent: 03 December 2004 12:28 | >| To: Simon Peyton-Jones | >| Subject: Re: [Template-haskell] Re: template-haskell names in 6.3 | >| | >| Simon Peyton-Jones wrote: | >| | >| Lets say we want to generate a recursive datatype, where there may | >already | >| be a name in scope from another module... we need: | >| | >| data Foo a = MkFoo (Module.Foo a) | >| | >| but we cannot use ''Foo to get the name as foo is not in scope yet. | >| | >| Keean. | >| | >| >now you've lost me. Just declare the constructor at the top level, | >and | >| >it'll get a global name. | >| > | >| >I don't see why you would ever want to make global name yourself. In | >| >Haskell we don't say | >| > | >| > data Foo.T = ... | >| > | >| >we just say | >| > | >| > data Foo = ... | >| > | >| >Simon | >| > | >| > | > | > | >
Simon Peyton-Jones wrote:
do you mean n <- newName s or let n = mkName s ?
I mean the latter... or perhaps: "n <- return $ mkName s"...
If the latter, you will get data Foo = Foo Foo
... and then I see what you want. You want a version of mkName that is like giving a qualified name in Haskell. It's dynamically scoped just like mkName, but it obeys the usual rules for qualified names in Haskell.
To be totally explicit, suppose I have
foo = [| mkQualName "Foo" "baz" |]
then if I call foo thus
wibble = \baz -> $foo
the $foo splice will expand to "Foo.baz", and that won't see the \baz; it'll see whatever Foo.baz is in scope.
This is exactly what I am after...
Is that what you seek? I can see it's reasonable. I'd need to add
mkQualName :: String -> String -> Name
That'd mean an extra form of Name. Currently, if you say 'Foo.baz you'll get a Name whose nameModule isn't necessarily Foo... it'll be the module that baz was actually defined in.
I'll leave that up to you, I don't mind if this translation happens, as long as it refers to the Foo.baz in dynamic scope the actuall name can change. Keean
participants (2)
-
Keean Schupke -
Simon Peyton-Jones