0

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!

4

2 回答 2

1

Krantz 的回答和更多阅读的帮助下,通过使用堆栈创建一个新项目来解决问题,以便 intero 知道我的源文件的位置。intero-global-mode因此,这个问题是由于 intero在 emacs中不知道在哪里寻找本地模块引起的。在这里,我将在这里写下我自己的答案,以进一步扩展Krantz的答案,并记录作为 Haskell 初学者解决此问题的过程:

为了使 intero 能够导入本地模块,我们应该避免使用intero-global-mode而是创建本地项目(事后看来这对我来说更有意义)。

因此,在本作业 2 的情况下,我不会将文件移动到问题中描述的作业文件夹,而是将stack new homework2源文件移动到homework2\src. 然后,当使用 emacs 加载时LogAnalysis.hs,我收到的不是之前的消息*intero:global-project::repl*

Loaded GHCi configuration from /Users/[username]/.stack/global-project/.stack-work/intero/intero-[script]

和加载时的错误消息LogAnalysis.hs,我现在可以得到:

Loaded GHCi configuration from /path/to/homework2/.stack-work/intero/intero-[script]

*intero:homework2:homework2:repl*. 现在使用C-c C-lto loadLogAnalysis.hs得到:

[2 of 2] Compiling LogAnalysis      ( /path/to/homework2/src/LogAnalysis.hs, interpreted ) [flags changed]
Ok, two modules loaded.

所以问题解决了。

于 2018-05-27T20:38:45.220 回答
1

似乎intero需要 apackage.yaml和 astack.yaml才能找到您的源文件。您可以只运行stack initstack new自动生成这些项目文件。
我多次遇到这个问题。上述方法解决了我在 Windows 和 Fedora 上的问题,希望对您有所帮助。

于 2018-05-27T11:50:30.840 回答