Collecting all external names in a module

Johan Tibell johan.tibell at gmail.com
Sat Sep 18 07:25:32 EDT 2010


Hi Simon,

Thanks for the pointers!

On Fri, Sep 17, 2010 at 6:29 PM, Simon Peyton-Jones
<simonpj at microsoft.com>wrote:

>  GHC already collects all RdrNames for imported things, for  use when
> reporting unused imports.  But it doesn’t collect the SrcSpan of the
> occurrences, nor does it collect occurrences of locally-bound things.
>

I found the spot where the collected RdrNames are used to generate the
unused import warnings, but I don't quite understand where they are
gathered. Is there an AST traversal function somewhere that gathers these
RdrNames? If so, I could use it as a blue print to write my own traversal.


> I suggest you write a general traversal looking like
>
>
>
> data Gather var res
>
>   = Gather { g_empty :: res
>
>                   , g_union :: res -> res -> res
>
>                   , g_occ :: Located var -> res
>
>                  , g_del :: Located var -> res -> res }
>
>
>
> getExpr :: Gather v res -> HsExpr v -> res
>
> .. and similarly for each other data type...
>

Could you expand a little bit on this design? Is the idea that the Gather
data type carries functions to apply in different parts of the AST? What's
"occ" short for, OccName? What about "del"?

There are different kind of ASTs (e.g. after renaming, after type checking,
etc), which one should I use if I want to gather all qualified names?

Thanks!

-- Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20100918/9036b633/attachment.html


More information about the Glasgow-haskell-users mailing list