12

Here is my scenario:

I'm working on a project with the following directories/modules:

|--proj
   |-- src
       |-- Foo
           |-- FooModule1.hs
           |-- FooModule2.hs
       |-- Bar
           |-- BarModule1.hs

BarModule1.hs looks like this:

module BarModule1 where

import Foo.FooModule1
...

I also have a .cabal file specifying src as the hs-source-dirs and of course both modules are listed in it.

When I am in the file BarModule1.hs in Emacs and I do C-c C-l it says:

proj/src/Bar/BarModule1.hs:3:8:
    Could not find module `Foo.FooModule1'
    Use -v to see a list of the files searched for.
Failed, modules loaded: none.

Also I want to use hlint with flymake-haskell-multi-load and if I activate that mode with M-x flymake-haskell-multi-load, hlint will always show the error that it can't find module Foo.FooModule1, because it is not aware of the .cabal file, in which I specify that hs-source-dirs: src.

So my question is: How can I make haskell-mode and flymake/hlint be aware of my project directory/module tree, so that it finds all modules?

Alternatively, how can I make them aware of the modules specified in my .cabal file?

itsjeyd
  • 5,070
  • 2
  • 30
  • 49
Stephen
  • 123
  • 1
  • 6
  • If you are using a cabal file, then why not use cabal itself? First make sure your current buffer is a file in the same folder as your .cabal file, then `C-u M-x compile RET cabal repl RET` – user2407038 Jun 26 '14 at 23:38
  • What version of haskell-mode are you using? The latest and greatest is very cabal aware. Same for ghc-mode IIRC – daniel gratzer Jun 27 '14 at 02:09
  • C-u M-x compile RET cabal repl RET works for the repl but does not fix the flymake/hlint issue I am using haskell-mode 13.7 – Stephen Jun 27 '14 at 05:45

3 Answers3

4

As for haskell-mode set haskell-process-type to cabal-repl in your emacs init file and make sure to use interactive-haskell-mode (not inf-haskell-mode):

(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
(setq haskell-process-type 'cabal-repl)
Thomas Bach
  • 157
  • 1
  • 8
3

My emacs configuration is based on Emacs Prelude. And I also create sandbox for the project with cabal sandbox init.

For the similar project structure haskell-mode works well. I am able to C-c C-l load current file into repl without errors. But flycheck is unable to resolve all modules and highlight import statements with errors:

Could not find module ‘Foo.FooModule1’
Use -v to see a list of the files searched for.

There is an issue Support Cabal sandboxes in GHC #293 with the solution. You need to create .dir-locals.el in the proj root which provides necessary variables.

((haskell-mode
  (flycheck-ghc-package-databases "/path/to/proj/.cabal-sandbox/x86_64-osx-ghc-7.6.3-packages.conf.d/")
  (flycheck-ghc-no-user-package-database . t)
  (flycheck-ghc-search-path "/path/to/proj/src")))
  • flycheck-ghc-package-databases - is a cabal.sandbox.config (you may need to create sandbox first) package-db setting
  • flycheck-ghc-search-path - is a path to proj/src
4e6
  • 10,696
  • 4
  • 52
  • 62
2

At the prompt in ghci: :set -iproj/src/

vivian
  • 1,434
  • 1
  • 10
  • 13
  • This fixes the C-c C-l problem, thanks. But still, flymake with hlint will not be affected by it, and still marks the first import line with "Could not find Module" – Stephen Jun 27 '14 at 05:41