Reputation: 85
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!
Upvotes: 0
Views: 1308
Reputation: 85
With the help of Krantz's answer and some more reading, the problem is solved by creating a new project with stack so intero knows the location of my source files.
Thus this problem is caused by intero's not knowing where to look for local modules when in intero-global-mode
in emacs.
Here I'll write my own answer here to expand Krantz's answer a little more, and to document the process of solving this problem as a beginner to Haskell:
For intero to be able to import local modules, we should avoid using intero-global-mode
and instead creating a local project (which in hindsight makes more sense to me).
So in the case of this Homework 2, instead of moving files to a homework folder as described in the question, I'll stack new homework2
, and move the sources files into homework2\src
. Then when using emacs to load LogAnalysis.hs
, instead of this previous message I got in *intero:global-project::repl*
:
Loaded GHCi configuration from /Users/[username]/.stack/global-project/.stack-work/intero/intero-[script]
and error message when loading LogAnalysis.hs
, I'm now able to get:
Loaded GHCi configuration from /path/to/homework2/.stack-work/intero/intero-[script]
in *intero:homework2:homework2:repl*
. And using C-c C-l
to load LogAnalysis.hs
now gets:
[2 of 2] Compiling LogAnalysis ( /path/to/homework2/src/LogAnalysis.hs, interpreted ) [flags changed]
Ok, two modules loaded.
So problem solved.
Upvotes: 1
Reputation: 906
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.
Upvotes: 1