Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果要为要导入的模块设置依赖项,请使用;Haskell工具堆栈";? 背景_Haskell_Haskell Stack - Fatal编程技术网

如果要为要导入的模块设置依赖项,请使用;Haskell工具堆栈";? 背景

如果要为要导入的模块设置依赖项,请使用;Haskell工具堆栈";? 背景,haskell,haskell-stack,Haskell,Haskell Stack,文件package.yaml中有多个位置可以设置依赖项 name:                Test1 ... extra-source-files: - README.md - ChangeLog.md ... dependencies: - base >= 4.7 && < 5 library:   source-dirs: src executables:   Test1-exe:     main:                Main.h

文件package.yaml中有多个位置可以设置依赖项

name:                Test1

...

extra-source-files:
- README.md
- ChangeLog.md

...

dependencies:
- base >= 4.7 && < 5

library:
  source-dirs: src

executables:
  Test1-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - Test1
    - directory

tests:
  Test1-test:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - Test1
…并像这样使用它

import qualified System.Directory as Dir
Dir.removeFile
我让舒尔知道,通过执行

stack install directory
在构建应用程序(“Main.hs”)和库(./src)时,编译器“说”

根据我在stackoverflow、google和此处搜索后阅读的内容”https://docs.haskellstack.org/en/stable/README/,并且为了包含包“目录”,我操纵了“stack.yaml”和“package.yaml”-但它不起作用,我也找不到解释如何使用该poperly的资源

实际问题 在何处为要导入的模块设置依赖项

笔记 一个类似的问题(“外部依赖,Haskell,stack:我应该修改一些东西还是“导入”假设足够?”)几乎回答了我的问题

虽然我仍然得到了反对票,但我不能删除这个问题,因为我已经得到了答案,这就是为什么我试图提供一个更准确的问题,并希望能够提供一个准确的答案,以及


另请参见我的第二条评论和下面新编辑的答案。

错误消息的相关部分如下:

也许您需要将
目录添加到.cabal文件中的构建依赖项中

如果要这样做:在
package.yaml
中,将
-目录
添加到第一个
依赖项:
字段

name:                xyz
version:             0.1.0.0
github:              "githubuser/xyz"
license:             none
author:              "..."
maintainer:          "...@..."
copyright:           "(c) 2021 ..."

extra-source-files:
- README.md
- ChangeLog.md

# ...
description:         Please see the README on GitHub at <https://github.com/...>

dependencies:
- base >= 4.7 && < 5
- directory

library:
  source-dirs: src
  ghc-options:
  - -O2
  - -threaded
  - -rtsopts
  - -with-rtsopts=-N

executables:
  xyz:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -O2
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - xyz

tests:
  xyz-test:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - xyz
进一步说明 许多人不使用
hpack
(他们删除
package.yaml
并直接编辑
.cabal
文件),这就是为什么如果使用
hpack
,您可能会发现很多文档不适用的原因

在您的例子中,
.cabal
文件是从
package.yaml
生成的。这是使用
hpack
工具完成的,默认情况下,该工具在
堆栈中使用

它转换为文件xyz.cabal,如下所示:

library
  exposed-modules:
      ...
  other-modules:
      Paths_xyz
  hs-source-dirs:
      src
  ghc-options: -O2 -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , directory
  default-language: Haskell2010

executable xyz
  main-is: Main.hs
  other-modules:
      Paths_genc3
  hs-source-dirs:
      app
  ghc-options: -O2 -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , directory
    , xyz
  default-language: Haskell2010

test-suite xyz-test
  type: exitcode-stdio-1.0
  main-is: Spec.hs
  other-modules:
      Paths_genc3
  hs-source-dirs:
      test
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , directory
    , xyz
  default-language: Haskell2010
库
公开模块:
...
其他模块:
路径xyz
hs源目录:
src
ghc选项:-O2-螺纹-rtsopts-带rtsopts=-N
构建取决于:

base>=4.7&&=4.7&&&=4.7&&&=4.7&&=谢谢。它有效。在“package.yaml”中,有多个位置显示“dependencies:”。它是它有效的顶级位置。在文件“package.yaml”(项目的顶级目录)中,“-”必须放在“dependencies:”下它没有缩进,并且不在可执行文件或测试下面!它(“-”)也必须在没有缩进的情况下放置,否则会出现类似“package.yaml:23:0:在解析块映射时未找到预期键”的错误。我将删除这些空格,但这也只是知道YAML对缩进敏感的问题;所有列表元素都必须缩进相同,但它们可以缩进。@Xia您介意我为您的答案添加一个示例吗?当然,请随意编辑我的答案。
dependencies:
  - base >= 4.7 && < 5
  - directory
library
  exposed-modules:
      ...
  other-modules:
      Paths_xyz
  hs-source-dirs:
      src
  ghc-options: -O2 -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , directory
  default-language: Haskell2010

executable xyz
  main-is: Main.hs
  other-modules:
      Paths_genc3
  hs-source-dirs:
      app
  ghc-options: -O2 -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , directory
    , xyz
  default-language: Haskell2010

test-suite xyz-test
  type: exitcode-stdio-1.0
  main-is: Spec.hs
  other-modules:
      Paths_genc3
  hs-source-dirs:
      test
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , directory
    , xyz
  default-language: Haskell2010