【问题标题】:stack ghci does not load local module but ghci doesstack ghci 不加载本地模块,但 ghci 加载
【发布时间】:2017-02-06 11:07:33
【问题描述】:

这类似于问题 stack ghci not loading up local modules? 但不完全相同。

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

如果我跑了

ghci Main.hs

一切正常。这是 7.10 版。

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

堆栈 ghci

:加载 Main.hs

我得到了错误

[1 of 1] 编译 Main(Main.hs,解释)

Main.hs:3:1: 错误:

无法加载“形状”的界面

它不是当前程序或任何已知包中的模块。

失败,已加载模块:无。

我尝试了链接上的解决方案

:加载 Shapes.hs Main.hs

但它仍然不起作用。我得到了错误

[1 of 2] 编译 Shapes(Shapes.hs,解释)

[2 of 2] 编译 Main(Main.hs,解释)

Main.hs:1:1: 错误:

IO 动作“main”未在模块“Main”中定义

失败,已加载模块:Shapes。

我发现以下内容讨论了第二个问题:

How to avoid "‘main’ is not defined in module ‘Main’" when using syntastic

但如果我要加入

main :: IO()

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

main = return ()

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

【问题讨论】:

    标签: haskell-stack


    【解决方案1】:

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

    模块主要在哪里

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

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

    :l Main.hs Shapes.hs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 2013-12-22
      • 1970-01-01
      • 2017-12-12
      • 1970-01-01
      相关资源
      最近更新 更多