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

Johan Tibell johan.tibell at gmail.com
Fri Apr 5 19:57:58 CEST 2013


Simon,

I've created a small standalone test case here:
https://gist.github.com/tibbe/5321268

Usage:

Download the Main.hs and Test.hs files into the same directory:

https://gist.github.com/tibbe/5321268/raw/68537a79865209d7218429b916a7ab1ccebc18e4/Main.hs
https://gist.github.com/tibbe/5321268/raw/f9cce61b35b3349eeeac622a4c27c1dd5e0410cf/Test.hs

Compile and run:
ghc Main.hs
./Main

Expected output:
Loading Test.hs ...
["Test.mysum","Data.List.foldl'","GHC.Num.+"]

Actual output:
Loading Test.hs ...
[".mysum","Data.List.foldl'","GHC.Num.+"]

Note how the locally defined and exported function mysum lacks a
module name. The code that creates a string from the Name is on line
59 in Main.hs:

    nameToString name = (maybe "" (moduleNameString . moduleName) .
nameModule_maybe $ name)
                        ++ "." ++ getOccString name

The module name is missing in the output because nameModule_maybe
returns Nothing for the mysum Name.

-- Johan



More information about the ghc-devs mailing list