haskellemacshaskell-mode

Emacs haskell intero mode, import could not find module


Edit: this error occurs only when using emacs haskell mode and intero mode (C-c C-l to load into ghci). It works in command line using stack ghc Log.hs LogAnalysis.hs.

I'm learning Haskell through CIS 194 (Spring 2013), and am running into this problem when doing homework 2. The homework folder is very simple:

homework2
|-- LogAnalysis.hs
|-- Log.hs
|-- error.log
|-- sample.log

Some data types are defined in Log.hs, and need to be imported into LogAnalysis.hs, which is the file I need to work on. The first few lines in LogAnalysis.hs are like this:

{-# OPTIONS_GHC -Wall #-}
module LogAnalysis where

import Log

-- Exercise 1: parse an individual message
...

However, I got error message like this in my emacs using haskell mode with intero:

error:
    Could not find module 'Log'
    Use -v to see a list of the files searched for.

(Hit 'C-c C-r' in the Haskell buffer to apply suggestions.)

Same message appears when using 'C-c C-l' to load to ghci within emacs.

But this error doesn't appear when loading LogAnalysis.hs in command line using stack ghci, the message is instead:

Prelude> :l LogAnalysis.hs
[1 of 2] Compiling Log              ( Log.hs, interpreted )
[2 of 2] Compiling LogAnalysis      ( LogAnalysis.hs, interpreted )
Ok, two modules loaded.
*LogAnalysis>

So I'm guessing this error has something to do with my emacs' setup of haskell mode and intero mode, but couldn't find any available solution yet.

Thanks for reading this question, your help will be appreciated!


Solution

  • It seems that intero needs a package.yaml and a stack.yaml in order to locate your source files. You can just run stack init or stack new to auto matically generate these project files.
    I met this problem several times. The above method solved my problem on my Windows and Fedora, so I hope this will help you.