[Haskell-cafe] possible bug in default module lookup scheme / or invalid haskell?

Carter Schonwald carter.schonwald at gmail.com
Sun Jul 18 03:59:16 EDT 2010

Hrm... my example also makes ghc flub too I think... (its been a long day).

is there anything implicitly going on behind this behavior that couldn't be
resolved by eg having the reasonable heuristic that for a module named *(Prefix
...).Name* in file *Name*, any import of the form* (Prefix ...).Blah* that
isn't a registered module should be searched for relative to the directory
containing the file *Name*? Ie, given a module A.B in directory A, the
prefix would be A, and thus we are looking for a module B.C relative to the
offset of  Directory A/. This doesn't seem to be create any ambiguity, it
just more intelligently uses explicitly available in the source

I don't think that semantics creates the sort of ambiguity that Kevin is
concerned about, and while yes there simple alternative approaches, they
require whatever is starting up ghci to know what the correct directory to
pass to the -i flag, and that seems a bit of a heavy weight expectation for
anything  that can't apriori  parse haskell modules (which would seem ironic
considering such tools typically use ghc's libraries for that task!)

On Sun, Jul 18, 2010 at 3:22 AM, Kevin Quick <quick at sparq.org> wrote:

> On Sat, 17 Jul 2010 22:45:57 -0700, Ivan Lazar Miljenovic <
> ivan.miljenovic at gmail.com> wrote:
>  Carter Schonwald <carter.schonwald at gmail.com> writes:
>>  Hello All, I'm not sure if this either a bug in how ghc does path/module
>>> lookup or  it simply is invalid haskell:
>>> consider modules A, A.B and A.B.C
>>> where  A imports A.B, and A.B imports A.B.C
>>> with the following file system layout
>>> A.hs
>>> A/B.hs
>>> A/B/C.hs
>>> minimal file examples:
>>> module A where
>>> import A.B
>>>  testA = "will it really really work?
>>> ------------
>>> module A.B where
>>> import A.B.C
>>>  testB = "will it work
>>> -----------------
>>> module A.B.C where
>>> testC = "will this work?"
>>> ----------
>>> if i run ghci A.hs everything's fine
>>> but if in directory B i rune ghci B.hs,  i get
>>> A/B.hs:2:8:
>>>    Could not find module `A.B.C':
>>>      Use -v to see a list of the files searched for.
>>> -----------
>>> it seems to me that if the default search path for ghc(i) includes the
>>> current directory (which according to docs it does), this shouldn't be
>>> happening.  (or is there some why this is good Behavior?)
>> I think ghci is just not smart enough to know that it should change to
>> the parent directory and run it from there.  As such, it's trying to
>> find "A.B.C" from the context of the current directory, and the file is
>> not in A/A/B/C.hs so it can't find it.
>> So it's just a limitation of ghci (I think).
> I'm afraid I disagree and would view this as expected behavior.
> "import A.B.C" translates internally to something like
> load_file_using_paths("A/B/C.hs").
> When you are running this from the top level directory (e.g. "top"), ghci
> includes the current path "top" so the lookup is for "top/A/B/C.hs", which
> clearly exists.
> When you are in directory B, ghci includes the current path "top/A/B" so
> the lookup is for "top/A/B/A/B/C.hs"... which does not exist, thus your
> error.
> Your example would require ghci to try load_file_using_paths("B/C.hs") (and
> then load_file_using_paths("C.hs") to be complete), which discards the
> directory heirarchy specified by the module nomenclature.  This is not
> adviseable because it introduces ambiguities.  For example, if you also had
> a C.hs in A and another C.hs in A/B, which C.hs should it load when you say
> "import A.B.C"?  Or "import C"? If ghc/ghci discarded paths, then the
> results would be either (1) a different C.hs depending on your current
> directory, (2) the bottom-most C.hs, (3) the C.hs in the current directory,
> (4) random?.  Worse, any of the above results in a trojan-horse style
> security hole.  Also, what if there was a C.hs in the directory above you
> (top/..)?  A 1:1 mapping between module heirarchy specification and
> directory paths is the only dependable mechanism.
> The better solution is to specifically set the paths you expect to form the
> roots of the (non-default) module heirarchy if you plan to work from within
> subdirectories of your source tree.  If you invoked ghci as "$ ghci -i
> /path/to/top" then it would work regardless of your current directory.  I
> believe that this is the proper solution to
> http://hackage.haskell.org/trac/ghc/ticket/3140 as well.
> -KQ
> --
> -KQ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100718/491d0c70/attachment.html

More information about the Haskell-Cafe mailing list