【问题标题】:Haskell Failed to load interface for moduleHaskell 无法加载模块的接口
【发布时间】:2018-08-16 02:51:09
【问题描述】:

您好,我正在尝试在另一个模块中使用一个模块,但它似乎无法正常工作。我尝试更新 cabal 文件、堆栈,我重新安装了平台、ghc 和所有内容,但它不会让它导入模块。我尝试在 cabal 文件中添加 other-modules 和 home-modules 部分..没有效果。可能是什么问题?

模块:

module Test where


    test::IO()
    test=do
        elem<-getLine
        print elem


module Main where

import Test

main :: IO ()
main = do
  putStrLn "hello world"

Cabal-build 呈现此错误:

$ cabal build

Resolving dependencies...
Configuring console-0.1.0.0...
Warning: To use the 'default-language' field the package needs to specify at
least 'cabal-version: >= 1.10'.
Preprocessing executable 'console' for console-0.1.0.0..
Building executable 'console' for console-0.1.0.0..

<no location info>: warning: [-Wmissing-home-modules]
    These modules are needed for compilation but not listed in your .cabal file's other-modules: Test

<no location info>: warning: [-Wmissing-home-modules]
    These modules are needed for compilation but not listed in your .cabal file's other-modules: Test

当我使用 Stack 构建时,出现此错误:

C:\<path>\Main.hs:4:1: error:
    Failed to load interface for `Test'
    Use -v to see a list of the files searched for.
Failed, modules loaded: none.
H>>= :module + *Main

阴谋文件:

 name:                console
version:             0.1.0.0
-- synopsis:
-- description:
homepage:            https://github.com/githubuser/console#readme
license:             BSD3
license-file:        LICENSE
author:              Bercovici Adrian Simon
maintainer:          example@example.com
copyright:           2018 Bercovici Adrian Simon
category:            Web
build-type:          Simple
cabal-version:       >=1.2
extra-source-files:  README.md


Executable console
  hs-source-dirs:      src
  main-is:             Main.hs
  default-language:    Haskell2010

  build-depends:       base                  >= 4.7    && < 5
  other-modules:       Test

【问题讨论】:

    标签: haskell visual-studio-code cabal


    【解决方案1】:

    other-modules: 指令必须放在Executable console 节内。

    【讨论】:

    • 注: The docs
    • 我也尝试过这个解决方案,但仍然是同样的问题。
    • @BercoviciAdrian 无法复制。向我们展示您认为包含我建议的修复但仍会产生这些消息的console.cabal 版本。
    • @BercoviciAdrian 你改变了两件事:你删除了你的build-depends: 行(为什么??),你移动了other-modules: 行。不要那样做。保持 build-depends: 行不变,other-modules 移动到 Executable console 节中。
    • @BercoviciAdrian 这对我来说听起来像是一个完全独立的问题。随意打开一个包含更多细节的新帖子!
    猜你喜欢
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 2021-01-11
    • 2015-02-09
    • 1970-01-01
    • 2016-10-09
    相关资源
    最近更新 更多