3

我最近阅读了 FRP 并开始对 Yampa 感兴趣。因为我已经安装过了,这里我只是检查一下它的安装情况。当我按照指示

$ cabal sandbox init         # Optional, but recommended
$ cabal update
$ cabal install Yampa

第三步的结果是:

cabal install Yampa
Resolving dependencies...
Up to date
Warning: You asked to install executables, but there are no executables in
target: Yampa. Perhaps you want to use --lib to install libraries instead.

所以我添加 --lib 并得到:

cabal install Yampa --lib
Resolving dependencies...
Up to date

然后我转向Vscode并写了一行:

import FRP.Yampa

我得到的是:

error:
    Could not find module ‘FRP.Yampa’
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
3 | import FRP.Yampa

我没有放弃,使用“ghc -v Yampa”搜索包:

wired-in package ghc-prim mapped to ghc-prim-0.5.3
wired-in package integer-wired-in mapped to integer-gmp-1.0.2.0
wired-in package base mapped to base-4.13.0.0
wired-in package rts mapped to rts
wired-in package template-haskell mapped to template-haskell-2.15.0.0
wired-in package ghc mapped to ghc-8.8.3



package flags [-package-id ghc-8.8.3{unit ghc-8.8.3 True ([])},
                   -package-id bytestring-0.10.10.0{unit bytestring-0.10.10.0 True ([])},
                   -package-id unix-2.7.2.2{unit unix-2.7.2.2 True ([])},
                   -package-id base-4.13.0.0{unit base-4.13.0.0 True ([])},
                   -package-id time-1.9.3{unit time-1.9.3 True ([])},
                   -package-id hpc-0.6.0.3{unit hpc-0.6.0.3 True ([])},
                   -package-id filepath-1.4.2.1{unit filepath-1.4.2.1 True ([])},
                   -package-id process-1.6.8.0{unit process-1.6.8.0 True ([])},
                   -package-id array-0.5.4.0{unit array-0.5.4.0 True ([])},
                   -package-id integer-gmp-1.0.2.0{unit integer-gmp-1.0.2.0 True ([])},
                   -package-id containers-0.6.2.1{unit containers-0.6.2.1 True ([])},
                   -package-id ghc-boot-8.8.3{unit ghc-boot-8.8.3 True ([])},
                   -package-id binary-0.8.7.0{unit binary-0.8.7.0 True ([])},
                   -package-id ghc-prim-0.5.3{unit ghc-prim-0.5.3 True ([])},
                   -package-id ghci-8.8.3{unit ghci-8.8.3 True ([])},
                   -package-id rts{unit rts-1.0 True ([])},
                   -package-id terminfo-0.4.1.4{unit terminfo-0.4.1.4 True ([])},
                   -package-id transformers-0.5.6.2{unit transformers-0.5.6.2 True ([])},
                   -package-id deepseq-1.4.4.0{unit deepseq-1.4.4.0 True ([])},
                   -package-id ghc-boot-th-8.8.3{unit ghc-boot-th-8.8.3 True ([])},
                   -package-id pretty-1.1.3.6{unit pretty-1.1.3.6 True ([])},
                   -package-id template-haskell-2.15.0.0{unit template-haskell-2.15.0.0 True ([])},
                   -package-id directory-1.3.6.0{unit directory-1.3.6.0 True ([])},
                   -package-id text-1.2.4.0{unit text-1.2.4.0 True ([])},
                   -package-id Ymp-0.13.1-433f4ae2{unit Yampa-0.13.1 True ([])}]

显然上面的最后一行是Yampa,但接下来是:

loading package database /usr/local/Cellar/ghc/8.8.3/lib/ghc-8.8.3/package.conf.d
loading package database /Users/.cabal/store/ghc-8.8.3/package.db
wired-in package ghc-prim mapped to ghc-prim-0.5.3
wired-in package integer-wired-in mapped to integer-gmp-1.0.2.0
wired-in package base mapped to base-4.13.0.0
wired-in package rts mapped to rts-1.0
wired-in package template-haskell mapped to template-haskell-2.15.0.0
wired-in package ghc mapped to ghc-8.8.3
*** Chasing dependencies:
Chasing modules from: *Yampa

<no location info>: error: module ‘Yampa’ cannot be found locally

我一直在尝试解决这个问题,但似乎没有与我的情况相关的问题。所以我真的需要你的帮助。谢谢!

-------------------------------------------------- ------update_2020_05_03------------------------------------------- -----

该文件是直接创建的(不使用“stack new”)。这意味着,我只需创建一个文本文件,在 VScode 中的文件夹“haskell_code”中输入一行“import FRP.Yampa”并将其名称更改为 helloworld.hs。

但是,如果我使用“stack new mystic”创建一个名为 mystic 的项目。并转到它的 main.hs。我仍然找不到 FRP.Yampa。这次我运行它时的错误消息有点不同:

error:
    Could not load module ‘FRP.Yampa’
    It is a member of the hidden package ‘Yampa-0.13.1’.
    You can run ‘:set -package Yampa’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import FRP.Yampa

因此,我修改了 mystic.cabal 文件,将 Yampa 添加到它的 build-depends 中(我没有使用 ':set -package Yampa' 因为每次我都必须输入这些东西)

我得到以下信息:

Error: While constructing the build plan, the following exceptions were encountered:

In the dependencies for mystic-0.1.0.0:
    Yampa needed, but the stack configuration has no specified version  (latest matching version
          is 0.13.1)
needed since mystic is a build target.

Some different approaches to resolving this:

  * Recommended action: try adding the following to your extra-deps
    in /Users/zhangkai/mystic/stack.yaml:

- Yampa-0.13.1@sha256:4612a2646c27bcd3ac55c90dbc34249303e28aa5b3bc3e0c6fa9ce58b889843c,5436


Error: Plan construction failed.

Warning: Build failed, but trying to launch GHCi anyway
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: mystic
GHCi, version 8.8.3: https://www.haskell.org/ghc/  :? for help
<command line>: cannot satisfy -package Yampa
    (use -v for more information)

我采纳了它的建议,将这一行添加到 stack.yaml 的 extra-deps

extra-deps:
- Yampa-0.13.1@sha256:4612a2646c27bcd3ac55c90dbc34249303e28aa5b3bc3e0c6fa9ce58b889843c,5436

有用。我还尝试了其他一些软件包。如果我创建一个 .hs 文件,我会失败。如果我创建一个项目并修改它的 .cabal 和 .yaml,它就可以工作。我想这可能与环境有关。这些包已下载但隐藏。

所以我的问题是:是否有任何解决方法可以让单个 .hs 文件(显然它既没有 .cabal 也没有 .yaml)也能看到包?

4

0 回答 0