<div dir="ltr">+1 on #2 and #3.<div><br></div><div>Being able to get all the packages that have a particular name sounds good! Note that if "-hide-package" / "-hide-all-packages" is used, I wouldn't want those packages in the results.</div><div><br></div><div>Considering that we also have the Module / ModuleInfo datatypes, to me it makes sense that we'd also be able to get a [Module] from a Package.</div><div><br><div><br></div><div>Like Dan, I'm a little less keen on #1. Here's why:</div><div><br></div><div>* PkgName is in the internal "Language.Haskell.TH.Syntax" module</div><div><br></div><div>* It isn't actually documented what it means, so it's meaning can be freely bent. There's no guarantee that you should be able to generate them.</div><div><br></div><div>* I couldn't find any examples of its usage that would be broken by this new semantics. I've done a search on github[1] to find usages of PkgName, and I only found one use[2] that uses PkgName which would be affected by this change. This example is in the TH lib itself, and so would hopefully be fixed by this change.<br></div><div><br></div><div>On the other hand, since it's rarely used, such an API breakage wouldn't be that impactful, so it's not that big of a deal.</div><div><br></div><div>[1] <a href="https://github.com/search?p=1&q=language%3Ahaskell+%22Language.Haskell.TH%22+%22PkgName%22+&ref=searchresults&type=Code&utf8=%E2%9C%93">https://github.com/search?p=1&q=language%3Ahaskell+%22Language.Haskell.TH%22+%22PkgName%22+&ref=searchresults&type=Code&utf8=%E2%9C%93</a></div><div>[2] <a href="https://github.com/phischu/fragnix/blob/fc98a1c6c486440ed047c8b630eb4e08041f52e4/tests/packages/scotty/Language.Haskell.TH.Quote.hs#L36">https://github.com/phischu/fragnix/blob/fc98a1c6c486440ed047c8b630eb4e08041f52e4/tests/packages/scotty/Language.Haskell.TH.Quote.hs#L36</a></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 1, 2015 at 10:09 AM, Edward Z. Yang <span dir="ltr"><<a href="mailto:ezyang@mit.edu" target="_blank">ezyang@mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In GHC 7.10, we changed the internal representation of names to<br>
be based on package keys (base_XXXXXX) rather than package IDs<br>
(base-4.7.0.1), however, we forgot to update the Template Haskell<br>
API to track these changes. This lead to some bugs in TH<br>
code which was synthesizing names by using package name and<br>
version directly, e.g. <a href="https://ghc.haskell.org/trac/ghc/ticket/10279" target="_blank">https://ghc.haskell.org/trac/ghc/ticket/10279</a><br>
<br>
We now propose the following changes to the TH API in order to<br>
track these changes:<br>
<br>
1. Currently, a TH NameG contains a PkgName, defined as:<br>
<br>
newtype PkgName = PkgName String<br>
<br>
This is badly misleading, even in the old world order, since<br>
these needed version numbers as well. We propose that this be<br>
renamed to PkgKey:<br>
<br>
newtype PkgKey = PkgKey String<br>
mkPackageKey :: String -> PackageKey<br>
mkPackageKey = PkgKey<br>
<br>
2. Package keys are somewhat hard to synthesize, so we also<br>
offer an API for querying the package database of the GHC which<br>
is compiling your code for information about packages. So,<br>
we introduce a new abstract data type:<br>
<br>
data Package<br>
packageKey :: Package -> PkgKey<br>
<br>
and some functions for getting packages:<br>
<br>
searchPackage :: String -- Package name<br>
-> String -- Version<br>
-> Q [Package]<br>
<br>
reifyPackage :: PkgKey -> Q Package<br>
<br>
We could add other functions (e.g., return all packages with a<br>
package name).<br>
<br>
3. Commonly, a user wants to get the package key of the current<br>
package. Following Simon's suggestion, this will be done by<br>
augmenting ModuleInfo:<br>
<br>
data ModuleInfo =<br>
ModuleInfo { mi_this_mod :: Module -- new<br>
, mi_imports :: [Module] }<br>
<br>
We'll also add a function for accessing the module package key:<br>
<br>
modulePackageKey :: Module -> PkgKey<br>
<br>
And a convenience function for accessing the current module:<br>
<br>
thisPackageKey :: Q PkgKey<br>
thisPackageKey = fmap (modulePackageKey . mi_this_mod) qReifyModule<br>
<br>
thisPackage :: Q Package<br>
thisPackage = reifyPackage =<< thisPackageKey<br>
<br>
Discussion period: 1 month<br>
<br>
Thanks,<br>
Edward<br>
<br>
(apologies to cc'd folks, I sent from my wrong email address)<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div><br></div>