Why do Names defined in the current module lack a module name?

Manuel M T Chakravarty chak at cse.unsw.edu.au
Wed Apr 3 14:23:42 CEST 2013


Johan Tibell <johan.tibell at gmail.com>:
> On Tue, Apr 2, 2013 at 3:31 AM, Simon Peyton-Jones
> <simonpj at microsoft.com> wrote:
> A bit, but it's still not clear to me exactly when user defined
> exported entities will have full (i.e. including module) names.
> 
>> Something that starts top-level may not finish up as top-level.  Nested bindings are never qualified.
>> 
>> After TidyPgm, externally-visible names (to the linker) are qualified, ones local to the .o file are not.
> 
> Here's my example program:
> 
> ```haskell
> module Test
>    ( mysum
>    ) where
> 
> import Data.List (foldl')
> 
> import Import (imported)
> 
> mysum :: [Int] -> Int
> mysum xs = foldl' (+) imported xs
> ```
> 
> As you see it has a top-level exported thing (mysum). My problem is
> that I'm traversing the type-checked AST (i.e. returned by
> `typecheckedSource module`) trying to collect all the names so I can
> index them for a code search project I'm working on. It's a bit
> similar to the GHC ctags/etags tool, except I'm trying to index all
> the source code.
> 
> So for every Name I run into in the source code I need to figure out
> what kind of name it is. That's made quite tricky by the fact that
> name resolution isn't actually quite done by the time we have the
> typed AST (i.e. mysum ought to have the name "Test.mysum", but it has
> the name "mysum"). I can try to implement this last resolution step
> myself, but then I need to understand how to identify names such as
> mysum above, while traversing the AST.

I'm not sure what information you are trying to collect, but if you can traverse the Core program after TidyPgm instead of the type checked AST, that would have all names cleaned up (as Simon wrote) and still have valid source positions.

Otherwise, there are predicates on 'Id's and 'Name's that determine their categories, e.g., 'isExportedId'. Just keep in mind that in GHC-speak a "local" 'Id' is one that is defined in the currently compiled module. It may still be a top-level 'Id' that is exported. (Not your classic definition of "local", I guess ;)

Manuel




More information about the ghc-devs mailing list