Collecting all external names in a module

Johan Tibell johan.tibell at gmail.com
Mon Sep 20 16:06:38 EDT 2010


On Mon, Sep 20, 2010 at 12:47 PM, Simon Peyton-Jones
<simonpj at microsoft.com>wrote:

>    Thomas had it right; it’s just a particular kind of fold.  The key
> parts of the traversal would be:
>
>
>
> ·        Occurrences.    getExpr g (HsVar v) = g_occ g v
>

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

    getExpr :: Gather v res -> LHsExpr v -> res
    getExpr g (L loc e) = case e of
        HsVar v -> g_occ g (L loc v)
        HsApp e1 e2 -> g_union g (getExpr g e1) (getExpr g e2)


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

I still don't quite the purpose of this, is it to say the v is now shadowing
whatever had the same name in the scope surrounding the lambda? Or is
"g_del" intended to mean "g_declaration" and capture the declaration sites
(and if so, how I know if it's a exported top-level declaration or not)?


>  Does that help?  Maybe one could generalise a bit.
>

Definitely. Thanks for the pointers.

Cheers,
Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20100920/4efec1b4/attachment.html


More information about the Glasgow-haskell-users mailing list