
When I'm developing Haskell code I like to frequently compile the file I'm currently working on so that the compiler will tell me if and where I've made mistakes. In my text editor I have a key mapped to do just that. I have another key mapped to fire up ghci with the current file so I can play around with the functions I've defined. I find this workflow to be very productive. I recently reorganized a project to take advantage of hierarchical modules and it broke my workflow. Now when I'm working in a subdirectory, say Foo where the modules are named Foo.Bar, Foo.Baz, Foo.etc., and I try to compile Bar.hs which imports Foo.Baz, the compiler looks for the file Foo/Baz.hs. The problem is that I'm already in the directory Foo and so the compiler fails to find the file for the module Foo.Baz. If I compile the whole project from the root project directory where the main file is, the compiler finds every module just fine. It seams very strange to me that when the compiler is compiling a module named Foo.Bar and there is an import for Foo.Baz, the compiler doesn't look in the directory where Foo.Bar is located (the current dir)! My temporary soluation has been to create symlinks to help the compiler find what it's looking for. For example in the Foo directory I have a symlink to that same Foo directory so that when compiling Bar.hs, the compiler finds Foo/Baz.hs when it looks for it. However, this seems like a dirty hack and it's not portable besides. Is this a known issue? Is there a better solution than mine? Is there something I'm missing? --Jargv

On 19 July 2010 14:31, Jonathan Geddes
Now when I'm working in a subdirectory, say Foo where the modules are named Foo.Bar, Foo.Baz, Foo.etc., and I try to compile Bar.hs which imports Foo.Baz, the compiler looks for the file Foo/Baz.hs. The problem is that I'm already in the directory Foo and so the compiler fails to find the file for the module Foo.Baz. If I compile the whole project from the root project directory where the main file is, the compiler finds every module just fine.
A similar query was just asked: http://www.haskell.org/pipermail/haskell-cafe/2010-July/080523.html
It seams very strange to me that when the compiler is compiling a module named Foo.Bar and there is an import for Foo.Baz, the compiler doesn't look in the directory where Foo.Bar is located (the current dir)!
Run ghc[i] from the root (source) directory of your project, not within the hierarchy (note that haskell-mode for emacs tries to do this by finding where the .cabal file is, etc.). -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

2010/7/19 Ivan Miljenovic
On 19 July 2010 14:31, Jonathan Geddes
wrote: Now when I'm working in a subdirectory, say Foo where the modules are named Foo.Bar, Foo.Baz, Foo.etc., and I try to compile Bar.hs which imports Foo.Baz, the compiler looks for the file Foo/Baz.hs. The problem is that I'm already in the directory Foo and so the compiler fails to find the file for the module Foo.Baz. If I compile the whole project from the root project directory where the main file is, the compiler finds every module just fine.
A similar query was just asked: http://www.haskell.org/pipermail/haskell-cafe/2010-July/080523.html
It seams very strange to me that when the compiler is compiling a module named Foo.Bar and there is an import for Foo.Baz, the compiler doesn't look in the directory where Foo.Bar is located (the current dir)!
Run ghc[i] from the root (source) directory of your project, not within the hierarchy (note that haskell-mode for emacs tries to do this by finding where the .cabal file is, etc.).
Alternatively, you can fire ghci with the -i option, e.g. ghci -i.. to look at the directory above (not there is no space between the -i and the ..). I do this to run tests which are located in a subdirectory. Otherwise I follow Ivan's advice of running from the root (which makes it easy to open any other file: sub-module, README, or .cabal). Cheers, Thu
participants (3)
-
Ivan Miljenovic
-
Jonathan Geddes
-
Vo Minh Thu