stack ghci 不加载本地模块,但 ghci 加载本地模块

stack ghci does not load local module but ghci does

这类似于 但不完全一样。

我有一个包含文件 Main.hs 和 Shapes.hs 的目录,其中 Main.hs 引用了 Shapes 模块。

如果我运行

ghci Main.hs

一切正常。这是 7.10 版本。

但如果我 运行,在版本 8 中,

stack ghci

:load Main.hs

我收到错误

[1 of 1] Compiling Main ( Main.hs, interpreted )

Main.hs:3:1: error:

Failed to load interface for ‘Shapes’

It is not a module in the current program, or in any known package.

Failed, modules loaded: none.

我在 link

上尝试了解决方案

:load Shapes.hs Main.hs

但还是不行。我收到错误

[1 of 2] Compiling Shapes ( Shapes.hs, interpreted )

[2 of 2] Compiling Main ( Main.hs, interpreted )

Main.hs:1:1: error:

The IO action ‘main’ is not defined in module ‘Main’

Failed, modules loaded: Shapes.

我找到了以下讨论第二件事的内容:

但是如果我输入

main :: IO ()

在 Main.hs 文件中,我仍然遇到错误。如果我要另外添加行

main = return ()

并在末尾添加这两行,然后它就会加载。但是加载后它只是退出 main 并且我无法再访问 main 中的函数。 当我导入其他模块时,我看不出有任何理由需要使用任何 IO 功能。在版本 8 中,如何在不使用 IO 的情况下加载本地模块?

我解决了自己的问题。在顶部的 Main.hs 中有一行叫做

module Main where

我删除了。现在,如果我使用

加载堆栈 ghci,它就可以工作了

:l Main.hs Shapes.hs