Collecting all external names in a module

Simon Peyton-Jones simonpj at
Mon Sep 20 17:56:35 EDT 2010

Don't I need to work on LHsExpr rather than HsExpr? How would I otherwise get the location?

Yes, indeed, LHsExpr.

*        Binding>          getExpr (Lam v e) = g_del v (getExpr g e)

I still don't quite the purpose of this

Well if you have (\x -> y + x)  there is a free occurrence of 'y' but not 'x'.  So take the occurrences in the body of the lambda and delete the ones for 'x', leaving only 'y'.

In general, use g_del (maybe badly named?  maybe g_bind?) whenever there's a binding site.

IDs occur in many places in the AST and I'm not sure which ones I should record (by calling g_occ) during my traversal. Should I only gather the ones in HsVar or are there other IDs of interest? As I explained in my first email, I'm looking for occurrences of 1) imported identifiers and 2) top-level identifiers defined in the current module. Should I be recording all IDs I find and the try to filter them out in my particular definition of Gather?

Well, your g_occ function can choose which occurrences to record.  (For others it can return g_empty).  The generic traversal doesn't need to know about that.

Do Ids appear in many places?  It seems to me to be mainly HsVar.  And VarPat for patterns, which are binding sites.

I'm also unsure which data types I should traverse, looking for LHsExpr. For example, LPat may contain view patterns that mention imported identifiers. Is there something in the HsExpr tree that I shouldn't traverse?
For now I'd look everywhere. (But until the typechecker has run don't look in fields of type PlaceholderType)


-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Glasgow-haskell-users mailing list