首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >堆栈自动删除“堆栈生成”之后的.cabal文件中的依赖项

堆栈自动删除“堆栈生成”之后的.cabal文件中的依赖项
EN

Stack Overflow用户
提问于 2020-12-14 16:45:26
回答 1查看 653关注 0票数 1

我想使用三重奏包来完成一个新的Haskell项目。

我做的第一件事是通过$ stack new threepennydemo创建一个堆栈项目。在这里,我做了以下几件事:

  1. 我从以下位置编辑了stack.yaml文件中的外挂部分:
代码语言:javascript
复制
# extra-deps: []

代码语言:javascript
复制
extra-deps:
  - threepenny-gui-0.9.0.0
  1. 我从以下位置编辑了.cabal文件:
代码语言:javascript
复制
library
  exposed-modules:
      Lib
  other-modules:
      Paths_threepennydemo
  hs-source-dirs:
      src
  build-depends:
      base >=4.7 && <5
  default-language: Haskell2010

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

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

代码语言:javascript
复制
library
  exposed-modules:
      Lib
  other-modules:
      Paths_threepennydemo
  hs-source-dirs:
      src
  build-depends:
      base >=4.7 && <5
    , threepenny-gui >= 0.9
  default-language: Haskell2010

executable threepennydemo-exe
  main-is: Main.hs
  other-modules:
      Paths_threepennydemo
  hs-source-dirs:
      app
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , threepennydemo
    , threepenny-gui >= 0.9
  default-language: Haskell2010

test-suite threepennydemo-test
  type: exitcode-stdio-1.0
  main-is: Spec.hs
  other-modules:
      Paths_threepennydemo
  hs-source-dirs:
      test
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , threepennydemo
    , threepenny-gui >= 0.9
  default-language: Haskell2010
  1. 我编辑了stock /app/Main.hs:
代码语言:javascript
复制
module Main where

import Lib

main :: IO ()
main = someFunc

代码语言:javascript
复制
import Graphics.UI.Threepenny
main :: IO ()
main = do
 startGUI defaultConfig showMessage
showMessage :: Window -> UI ()
showMessage window = do
 getBody window #+ [string "Hello, world!"]
 return ()
  1. 我输入命令$ stack build

从这里,我注意到两件事。首先,我收到以下错误:

代码语言:javascript
复制
Building all executables for `threepennydemo' once. After a successful build of all of them, only specified executables will be rebuilt.
threepennydemo> configure (lib + exe)
Configuring threepennydemo-0.1.0.0...
threepennydemo> build (lib + exe)
Preprocessing library for threepennydemo-0.1.0.0..
Building library for threepennydemo-0.1.0.0..
Preprocessing executable 'threepennydemo-exe' for threepennydemo-0.1.0.0..
Building executable 'threepennydemo-exe' for threepennydemo-0.1.0.0..
[1 of 2] Compiling Main

/Users/my_username/threepennydemo/app/Main.hs:1:1: error:
    Could not load module ‘Graphics.UI.Threepenny’
    It is a member of the hidden package ‘threepenny-gui-0.9.0.0’.
    Perhaps you need to add ‘threepenny-gui’ to the build-depends in your .cabal file.
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
1 | import Graphics.UI.Threepenny
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


--  While building package threepennydemo-0.1.0.0 using:
      /Users/my_username/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.4 --builddir=.stack-work/dist/x86_64-osx/Cabal-3.0.1.0 build lib:threepennydemo exe:threepennydemo-exe --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

第二种情况是,我的.cabal文件(如2.中提到的那样)已经自动删除了我对该文件所做的编辑。

在设置新的堆栈项目时,为了能够使用第三方库,我遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-14 17:58:45

我的困难是由于stack.yamlpackage.yaml之间的一些混淆。后者是生成threepennydemo.cabal文件的原因。因此,还必须将依赖项指定为package.yaml文件。将此依赖项添加到package.yaml使$ stack build能够在没有问题的情况下完成。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65292929

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档