Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell-mode not working for my project, can't find module

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?

like image 921
Stephen Avatar asked Jun 26 '14 23:06

Stephen


2 Answers

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)
like image 77
Thomas Bach Avatar answered Sep 30 '22 18:09

Thomas Bach


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
like image 34
4e6 Avatar answered Sep 30 '22 18:09

4e6