
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

"Casey Rodarmor"
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@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

On Sun, Sep 28, 2008 at 6:08 PM, Chry Cheng
"Casey Rodarmor"
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@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. Can anyone give a little insight into why this decision was made? Best, Casey

On Mon, Sep 29, 2008 at 12:20 AM, Casey Rodarmor
On Sun, Sep 28, 2008 at 6:08 PM, Chry Cheng
wrote: "Casey Rodarmor"
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@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@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Sun, Sep 28, 2008 at 7:33 PM, Christian Cheng
On Mon, Sep 29, 2008 at 12:20 AM, Casey Rodarmor
wrote: On Sun, Sep 28, 2008 at 6:08 PM, Chry Cheng
wrote: "Casey Rodarmor"
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@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.
I was fooling around with Java, and you're totally right, the module itself must know about its full name, so you can't have a java file which declares itself as "package Foo.Thingy;" in Bar/Foo/Thingy.java, and then do an "import Bar.Foo.Thingy". It is worth noting that in C and C++, a double-quoted #include will search relative to the current source file. Even though that doesn't have anything to do with locating the object file that you'll probably want to link in later... The comparison I was thinking of was with python, where a module can be placed in an arbitrary directory, and then accessed using a relative path. If I have 'stuff.py' that contains class 'Foo', I can move it to 'hello/module/stuff.py', and then import it is hello.module.stuff. A python module doesn't need to know where it lives. I often find myself working on computers where I don't have administrative privileges, which means I might not be able to install libraries in the 'right' places. This approach also makes it simple to create self-contained projects that can easily be moved from machine to machine, where only the local directory structure is important. Would there be any downside to this in haskell?
Can anyone give a little insight into why this decision was made?
Best, Casey _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On 2008 Sep 28, at 14:17, Casey Rodarmor wrote:
I often find myself working on computers where I don't have administrative privileges, which means I might not be able to install libraries in the 'right' places. This approach also makes it simple to create self-contained projects that can easily be moved from machine to machine, where only the local directory structure is important. Would there be any downside to this in haskell?
Take a look at "ghc-pkg --user". -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

2008/9/28 Casey Rodarmor
The comparison I was thinking of was with python, where a module can be placed in an arbitrary directory, and then accessed using a relative path. If I have 'stuff.py' that contains class 'Foo', I can move it to 'hello/module/stuff.py', and then import it is hello.module.stuff.
And if you have something in hello/ it must refer to the same module by module.stuff instead. I'm not sure it's clearer... Anyway the hierarchical modules in Haskell means that every code must import the same module with the same name which I find saner (though I could wish the import/export syntax would be more advanced to allow for shorter imports when I have a lot of imports in the same hierarchy part).
A python module doesn't need to know where it lives.
Well, it doesn't need to, but everyone else needs to, in Haskell, the module need to know where it lives, but everyone else don't care.
I often find myself working on computers where I don't have administrative privileges, which means I might not be able to install libraries in the 'right' places. This approach also makes it simple to create self-contained projects that can easily be moved from machine to machine, where only the local directory structure is important. Would there be any downside to this in haskell?
Note that if the modules are in the same project, they're all in the same hierarchy (at least that's how I see a project) and so their names are coherent with each other and with the relative directory hierarchy, there is no problem there. Now, I think your preoccupation has more to do with packaging several libraries you're not sure will be available on the final machine with your project, and reasonably, you don't want to put them all in the same base directory (yeah, it would be a mess). I would argue that Haskell being a compiled language, its distribution problematics aren't exactly the same as Python... If you're just distributing an application you presumably would just compile it on your development setup and then distribute the executable. But if you really want to distribute the code source in a self sufficient package (assuming GHC on the final machine I guess ?), you should use Cabal : it automates dependency checking, compilation and installation with several source directory and configurable target installation directory. It's pretty easy to use too (mainly I suggest you do copy/paste of a good project file on Hackage). -- Jedaï

2008/9/28 Casey Rodarmor
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.
Can anyone give a little insight into why this decision was made?
Because that's how every language worked for decades for good reasons : a library usually stay in one place on the filesystem while several projects from several locations try to use it. So of course we would prefer for each of these projects source to refer to the library in the same fashion, especially given that it can be moved later on or split between different buildtree or ... Now, you may not be aware of that but you can register a library so that GHC always know where to find its module, as long as you use --make on the command line : ghc --make myScript.hs . -- Jedaï
participants (5)
-
Brandon S. Allbery KF8NH
-
Casey Rodarmor
-
Chaddaï Fouché
-
Christian Cheng
-
Chry Cheng