RE: module namespaces with "Prelude"

On Thursday, April 25, 2002, at 11:30 , Simon Marlow wrote:
All in all, dropping all implicit directories from the search path gets my vote.
"me too".
I wasn't aware that Hugs did this, and GHCi certainly doesn't. It's reasonable to leave "." in the default search path, but adding an implicit root for an imported module will certainly lead to trouble - after all, we use hierarchical module names because the modules at the leaves of the tree are expected to overlap.
But it is this "." in the default path that is the reason GHCi gives unexpected results, isn't it? [See Hal Daume's original bug report]
Well, that depends what you mean by unexpected - IMHO the behaviour is entirely reasonable and is well documented. Let's recap: the directory structure is something like this (using $$ to represent an arbitrary path): $$/Bar/Foo.hs contains module Bar.Foo $$/Bar/IO.hs contains module Bar.IO now if the current directory is $$, then Bar.Foo and Bar.IO map to the correct filenames/modules. However, if the current directory is $$/Bar, as it was in Hal's example, then module IO maps to both ./IO.hs and the IO module in the standard library. Clearly there's an overlap, and the solutaion is not to sit in $$/Bar, or to explicitly remove "." from the default search path (which you can do in ghc by giving a -i option without any arguments). If one root is a subdirectory of another root, then you have an overlap. Clearly, the "implicit roots" mechanism will always lead to overlap, so it can't be the right thing to do. Unfortunately it isn't easy to detect whether the user-specified roots are overlapped and issue a warning, but I think the rule is fairly straightforward to understand. It would be possible to detect whether a module maps to more than one filename though - perhaps we should do that. Cheers, Simon

All in all, dropping all implicit directories from the search path gets my vote.
"me too".
I vote for this provided "." isn't implicitly in the search path either. Or, rather, I vote for that assuming that my proposal [see below] isn't going to be accepted, which I'm pretty sure it won't, but I'll put it out there anyway. As I see it, a large part of the problem comes when using the interpreters, not the compilers. Why? Because we can specify *either* module names *or* file names as the parameters to :load. Proposal: you may *only* specify module name as the parameter to load. Then, when loading this module, if it's name is X.Y then take the *first* x in the search path such that there exists a file x/X/Y.(l)hs and load this file. If you make sure that "." isn't in the search path, my initial problem goes away. If someone always wants "." in the search path, then they can say -i. which I don't think is a big deal. Or, if you don't want to upset people, you could have "." in the search path but have an option --no-implicit-dot to turn it off which I would just put as a default option. The only thing this breaks is modules named Main, which I don't like anyway. I think that any module that exports a function main of type IO () should be able to be compiled as an executable. So I could have a main :: IO () in my NLP.Foo.Bar.FooBar module and would be able to compile that without changing the module name. <-- this is why i don't think this proposal will be used. So, my vote is for nothing implicit in the search path, including ".", barring that, have a --no-implicit-dot option. - Hal
participants (2)
-
Hal Daume III
-
Simon Marlow