0

我想使用threepenny-gui包处理一个新的Haskell 项目。

我做的第一件事是通过$ stack new threepennydemo. 从这里,这里,我做了以下事情:

  1. 我从以下位置编辑了 stack.yaml 文件中的 extra-deps 部分:
# extra-deps: []

extra-deps:
  - threepenny-gui-0.9.0.0
  1. 我从以下位置编辑了 .cabal 文件:
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

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. 我从以下位置编辑了股票 /app/Main.hs:
module Main where

import Lib

main :: IO ()
main = someFunc

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

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

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. 中所述编辑,已自动删除我对文件所做的编辑。

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

4

1 回答 1

1

我的困难是由于 和 之间的一些stack.yaml混淆package.yaml。后者是生成threepennydemo.cabal文件的原因。因此,还必须为package.yaml文件指定依赖关系。将此依赖项添加到package.yaml允许$ stack build完成而不会出现问题。

于 2020-12-14T17:58:45.197 回答