<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">@Simon,</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">The route you outline was the one we already use -- but that gives back </div><div class="gmail_default" style="font-family:monospace,monospace">the full name "Data.Set.Base.Set" (instead of "S.Set" or "Data.Set.Set"),</div><div class="gmail_default" style="font-family:monospace,monospace">as the module is "Data.Set.Base". </div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">@Edward,</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Yes, I think your suggestion should work! This business of determining</div><div class="gmail_default" style="font-family:monospace,monospace">which packages/modules are hidden is exactly what we are trying to get </div><div class="gmail_default" style="font-family:monospace,monospace">around. (In this case, Data.Set.Base is hidden...)</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Thanks all!</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">- Ranjit.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 25, 2017 at 1:00 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">Hi Ranjit,<br>
<br>
Unfortunately you need more information to do this, since the<br>
set of modules which are available for import can vary depending<br>
on whether or not packages are hidden or not (not even counting<br>
whether or not a module is exposed or not!)<br>
<br>
The way GHC's pretty printer gives a good name is that it keeps<br>
track of all of the names in scope and where they came from<br>
in a GlobalRdrEnv.  The relevant code is in 'mkPrintUnqualified'<br>
in HscTypes, but if you pretty print using user-style with<br>
an appropriately set up GlobalRdrEnv you should<br>
get the things you want.<br>
<br>
Edward<br>
<br>
Excerpts from Ranjit Jhala's message of 2017-01-24 19:00:05 -0800:<br>
<div class="HOEnZb"><div class="h5">> Dear Joachim,<br>
><br>
> You are right -- some more context.<br>
><br>
> Given<br>
><br>
>   tc  :: TyCon<br>
>   m   :: ModName<br>
>   env :: HscEnv<br>
><br>
> I want to get a<br>
><br>
>   s :: String<br>
><br>
> such that _in_ the context given by `m` and `env` I can resolve `s` to get<br>
> back the original `TyCon`, e.g. something like<br>
><br>
>   L _ rn <- hscParseIdentifier env s<br>
>   name   <- lookupRdrName env modName rn<br>
><br>
> would then return `name :: Name` which corresponds to the original `TyCon`.<br>
><br>
> That is, the goal is _not_ pretty printing, but "serialization" into a<br>
> String<br>
> representation that lets me recover the original `TyCon` later.<br>
><br>
> (Consequently, `"Data.Set.Base.Set"` doesn't work as the `Data.Set.Base`<br>
> module is hidden and hence, when I try the above, GHC complains that the<br>
> name is not in scope.<br>
><br>
> Does that clarify the problem?<br>
><br>
> Thanks!<br>
><br>
> - Ranjit.<br>
><br>
><br>
> On Tue, Jan 24, 2017 at 6:11 PM, Joachim Breitner <<a href="mailto:mail@joachim-breitner.de">mail@joachim-breitner.de</a>><br>
> wrote:<br>
><br>
> > Hi Ranjit,<br>
> ><br>
> > Am Dienstag, den 24.01.2017, 16:09 -0800 schrieb Ranjit Jhala:<br>
> > > My goal is to write a function<br>
> > ><br>
> > >    tyconString :: TyCon -> String<br>
> > ><br>
> > > (perhaps with extra parameters) such that given the<br>
> > > `TyCon` corresponding to `Set`, I get back the "original"<br>
> > > name `S.Set`, or even `Data.Set.Set`.<br>
> > ><br>
> > > Everything I've tried, which is fiddling with different variants of<br>
> > > `PprStyle`, end up giving me `Data.Set.Base.Set`<br>
> > ><br>
> > > Does anyone have a suggestion for how to proceed?<br>
> ><br>
> > in a way, `Data.Set.Base.Set` is the “original”, proper name for Set,<br>
> > everything else is just a local view on the name.<br>
> ><br>
> > So, are you maybe looking for a way to get the “most natural way” to<br>
> > print a name in a certain module context?<br>
> ><br>
> > This functionality must exist somewhere, as ghci is printing out errors<br>
> > this way. But it certainly would require an additional argument to<br>
> > tyconString, to specify in which module to print the name.<br>
> ><br>
> > Greetings,<br>
> > Joachim<br>
> ><br>
> ><br>
> > --<br>
> > Joachim “nomeata” Breitner<br>
> >   <a href="mailto:mail@joachim-breitner.de">mail@joachim-breitner.de</a> • <a href="https://www.joachim-breitner.de/" rel="noreferrer" target="_blank">https://www.joachim-breitner.<wbr>de/</a><br>
> >   XMPP: <a href="mailto:nomeata@joachim-breitner.de">nomeata@joachim-breitner.de</a> • OpenPGP-Key: 0xF0FBF51F<br>
> >   Debian Developer: <a href="mailto:nomeata@debian.org">nomeata@debian.org</a><br>
> > ______________________________<wbr>_________________<br>
> > Glasgow-haskell-users mailing list<br>
> > <a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.<wbr>org</a><br>
> > <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/glasgow-<wbr>haskell-users</a><br>
> ><br>
> ><br>
</div></div></blockquote></div><br></div>