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

Johan Tibell johan.tibell at gmail.com
Tue Apr 2 18:43:21 CEST 2013


Hi Simon,

On Tue, Apr 2, 2013 at 3:31 AM, Simon Peyton-Jones
<simonpj at microsoft.com> wrote:
>
> Does this help
>
> http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/NameType

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.

-- Johan



More information about the ghc-devs mailing list