[Haskell-beginners] Module import problem

Christian Cheng chrycheng at gmail.com
Sun Sep 28 13:33:34 EDT 2008


On Mon, Sep 29, 2008 at 12:20 AM, Casey Rodarmor
<caseyrodarmor at gmail.com> wrote:
>
> On Sun, Sep 28, 2008 at 6:08 PM, Chry Cheng <chrycheng at gmail.com> wrote:
> > "Casey Rodarmor" <caseyrodarmor at gmail.com> writes:
> >
> >> Hi there!
> >>
> >> I have a problem with importing a module I'd like to use.
> >>
> >> My working directory, ~/proj, contains:
> >>    ./Haskore -- a folder containing a version of haskore, this music thingy
> >>    ./test.hs -- random stuff using haskore
> >>
> >> The main file in ~/proj/Haskore is ~/proj/Haskore/Haskore.hs, which
> >> contains the following module declaration:
> >>> module Haskore(module HaskoreLoader) where
> >>> import HaskoreLoader
> >>
> >> I've tried to put all the following in ~/proj/test.hs, with no luck:
> >>> import Haskore         -- Could not find module `Haskore':
> >>> import Haskore.Haskore -- file name does not match module name `Haskore'
> >>
> >> Am I doing something wrong? Is there a way to place a module in an
> >> arbitrary directory, without having to modify it?
> >>
> >> Thanks so much for your help!
> >>
> >> Best,
> >> Casey Rodarmor
> >> _______________________________________________
> >> Beginners mailing list
> >> Beginners at haskell.org
> >> http://www.haskell.org/mailman/listinfo/beginners
> >
> > You have to tell GHC where to find Haskore.  To do this, call ghc with the i option:
> >
> > ghc -iHaskore/
> >
> > then, import using:
> >
> > import Haskore
> >
>
> Hi Chry,
>
> Thanks for the answer, everything works now :-)
>
> I must admit, I'm a little disappointed if that's the only way to get
> it to work. On the surface of things, I don't see why one can't just
> put a Module in some/arbitrary/directory, and then import it as
> some.arbitrary.directory.Module. The need to use a flag on the command
> line seems a little unnecessary.
>

I beg to differ.  I don't think it's reasonable to expect the compiler
to figure out on its own where we have stashed additional classes.
Other programming languages have a similar requirement.  For Java,
it's the class path (e.g., javac -classpath Haskore); C/C++, the
include directories (IIRC, gcc -I Haskore), etc.

> Can anyone give a little insight into why this decision was made?
>
> Best,
> Casey
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners


More information about the Beginners mailing list