full :browse! (#1617, draft patch, and a question)
claus.reinke at talk21.com
Mon Sep 10 12:58:39 EDT 2007
>You want to know how the thing was brought into this lexical scope,
>so you need to consult the current GlobalRdrEnv. See
>To do what you want:
>* Get the OccName of the thing
>* Look that up in the GlobalRdrEnv, to get a [GlobalRdrElt]
>* Of these, at most one will have gre_name == the Name of the thing
>* Look at the gre_prov for that GRE
>The provenance tells you how it is in scope (perhaps in multiple ways).
>Does that help?
yes, thanks! that does exactly what i was looking for. although almost
none of it is in scope where i need it (InteractiveUI.hs), so i have to
figure out if i can move some of my code somewhere else, to avoid
all those extra imports. but, roughly, i now have:
map gre_prov . lookupGRE_Name rdr_env . getName
just to make certain i understand that double list:
[GlobalRdrElt] : different things with the same unqualified name
[ImportSpec] : different qualified names for the same thing
in the context of ghci's :browse, it appears that unqualified names
that would cause conflicts are simply not in scope (only their
separate qualified forms are), so the [GlobalRdrElt] for a Name
should always have length 1, correct?
>The commentary is obviously deficient; could you spend a few
>mins updating it so that you'd have been able to find this info
i wouldn't phrase it as harshly;-) it is more a matter of usage/
perspective: if i had read the whole commentary recently, it
would have occurred to me that this part answers my question.
but i read it long ago, and didn't have a concrete application
in mind, so i forgot most of it again. today, i have a concrete
application in mind, but a commentary is no reference.
so i don't think that adding to the main text alone would help
people like me, who would need an index or a how-to faq.
but trying to keep an entirely separate index or faq in sync
with the main text seems hopeless as well.
in light of this, my suggestion for improvement would be
to embedd individual faq answers directly into the main
text, with a special tag, and to have a separate faq page,
which would do nothing but gather those tags from the
main text in a single collection (preferably automatically).
the entry i'd like to add (after the explanation of the
GlobalRdrEnv types) would look somewhat like this
(slightly generalised from my question, since your answer
covers more ground):
How do I find import information for a Name in scope?
Use the GlobalRdrEnv (compiler/basicTypes/RdrName.lhs):
* Get the OccName of the thing
* Look that up in the GlobalRdrEnv, to get a [GlobalRdrElt]
* Of these, at most one will have gre_name == the Name of the thing
* Look at the gre_prov for that GRE
The provenance tells you how it is in scope (perhaps in multiple ways).
(or some non-XML format suitable for scripted extraction)
this way, simply editing the main commentary text would
also update an automatically generated how-to faq page
(a bit like the way latex generates indices?). thus catering
both for people who want to read the whole thing as a
consistent text and for those who need to find information
on how to achieve a specific task.
i have a similar problem with the sources: i don't read all
of them if i only want to make a small change to ghci, so
i'm using InteractiveUI.hs and GHC.hs as my main entry
points and reference index: if i know how what i want to
do relates to something i know where to find, i can start
from there, but sometimes, nothing similar exists, or the
functionality is implicit or provided under a different name
or in a different module (in this case, i should have thought
of the ambiguous import errors as a starting point!-).
More information about the Cvs-ghc