简体   繁体   English

为什么 ghc (Haskell) 编译器找不到我导入的模块 Data.Vector? 我收到错误:找不到模块“Data.Vector”

[英]Why can't the ghc (Haskell) compiler find the module Data.Vector which I have imported? I get the error: Could not find module 'Data.Vector'

vector module has been installed by "cabal install vector"向量模块已由“cabal install vector”安装

bash-3.2$ ghc-pkg list -f $HOME/.cabal/store/ghc-9.2.1/package.db 
/Users/gcolpitts/.cabal/store/ghc-9.2.1/package.db
    primitive-0.7.3.0
     vector-0.12.3.1 

but the compiler can't find it:但编译器找不到它:

$ ghc prob214ff.hs
[1 of 1] Compiling Main             ( prob214ff.hs, prob214ff.o )

prob214ff.hs:14:1: error:
    Could not find module ‘Data.Vector’
    Perhaps you meant Data.Functor (from base-4.16.0.0)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
   |
14 | import Data.Vector

Thx @n.谢谢@n。 1.8e9-where's-my-share ! 1.8e9-我的分享在哪里!

 ghc -package-db $HOME/.cabal/store/ghc-9.2.1/package.db  prob214ff.hs 

solves my problem although it is a regression from previous versions of ghc which didn't require the use of the -package-db option.解决了我的问题,尽管它是从以前版本的 ghc 回归,不需要使用 -package-db 选项。

I'd love to use GHC_PACKAGE_PATH but I can't see how to make that work.我很想使用 GHC_PACKAGE_PATH 但我不知道如何使它工作。 Sec 5.9.5 of the ghc users guide is confusing. ghc 用户指南的第 5.9.5 节令人困惑。 It states "A package database is where the details about installed packages are stored. It is a directory, usually called package.conf.d."它指出“包数据库是存储有关已安装包的详细信息的地方。它是一个目录,通常称为 package.conf.d。” ie not the package.db file that I gave with -package-db on the command line.即不是我在命令行上用 -package-db 给出的 package.db 文件。 But where is the package.conf.db directory with info on the vector package that I installed with cabal?但是包含有关我使用 cabal 安装的矢量包的信息的 package.conf.db 目录在哪里?

"ghc-pkg list" references /usr/local/lib/ghc-9.2.1/lib/package.conf.d but the output of the command doesn't list the vector package I installed. “ghc-pkg list”引用 /usr/local/lib/ghc-9.2.1/lib/package.conf.d 但命令的输出没有列出我安装的矢量包。

"ghc-pkg list -f $HOME/.cabal/store/ghc-9.2.1/package.db" does list the vector package in it's output but doesn't tell me a package.conf.d directory that knows about the vector package. “ghc-pkg list -f $HOME/.cabal/store/ghc-9.2.1/package.db”确实在它的输出中列出了矢量包,但没有告诉我一个 package.conf.d 目录知道矢量包。

This is a bit fiddly with cabal version 2. Installing packages no longer really makes sense (despite the cabal install still existing...).这对于 cabal 版本 2 来说有点繁琐。安装软件包不再真正有意义(尽管cabal install仍然存在......)。 Instead you will probably find it easiest to create a cabal package instead, for example:相反,您可能会发现创建 cabal 包最容易,例如:

$ mkdir my-package
$ cd my-package 
$ cabal init
<Edit my-package.cabal and add vector to the build-depends line>
<Put the contents of prob214ff.hs in app/Main.hs instead>
$ cabal run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM