Template Haskell changes to names and package keys

Edward Z. Yang ezyang at mit.edu
Sun May 3 20:22:00 UTC 2015

> I didn't search for that, since I was searching for explicit uses of
> PkgName.  The results for NameG are pretty interesting, though:
> https://github.com/search?l=haskell&q=NameG&type=Code&utf8=%E2%9C%93
> It seems like most of the results are either `Lift`ing a PkgName or
> re-using a PkgName from another name.  However, there are a fair number of
> uses which explicitly construct the name, though.  In particular, there are
> a fair number of usages of this to generate references to the tuple
> constructors in GHC.Prim.
> Interestingly, these usages of (mkPkgName "ghc-prim") don't have version
> numbers at all.  This implies that the behavior is to select the version of
> the package which is currently being used.

Well, the reason they don't have version numbers is because ghc-prim
(and a few other packages) are internally considered wired-in packages,
so their package keys are always some specific, hard-coded value.
There is no "implied behavior", it's just an implementation detail that
this TH API happens to expose.  (There is one concrete consequence of
this, which is that it's not possible to have two versions of ghc-prim
simultaneously in the same executable.)

Prior to 7.10, this manifested as ghc-prim having PkgName
"ghc-prim", but lens having PkgName "lens-0.3.2".

> So, how about for this rare-ish case where there we're linking against two
> different versions of the foo package, and the TH manually generates a
> (PkgName "foo"), we generate an ambiguity error.
> If we force users to search for and specify fully unambiguous package names
> then that pushes the boilerplate of package selection out to TH usage.  It
> seems like pretty much everyone will want "select the version of the
> package that I'm using."  That said, I'm also in favor of adding the
> function mentioned in #2, for those cases where the default isn't
> sufficient (I'm anticipating very few of these).

I looked at the results.

    This is just very wrong, they should clearly switch to thisPackageKey when we have it

    I'm not really sure what this is supposed to be, besides some
    meta-meta-programming library. It's clearly prototype code and I
    don't think they will mind if it stops working.

    So, this piece of code is something that really ought to be in the
    standard library, if it isn't already.  Basically, the problem is
    that when you quote an identifier, e.g. [| foo |], you get the
    *un-renamed* syntax (a variable foo) rather than the renamed syntax
    (somepkg:Data.Foo.foo).  This is very useful, too useful to be in
    another library.

    Wouldn't be broken.

    This (and the next page of results) are from the template-haskell
    library. We can fix these ourselves when we make these changes.

To sum up, I still think we should rename, and I think we should
also add some functionality to the standard library for getting the
renamed version of a TH syntax tree.


More information about the Libraries mailing list