gpt4 book ai didi

haskell - 在沙箱中安装了 parsec,但在 ghci 中尝试加载文件时找不到库

转载 作者:行者123 更新时间:2023-12-03 13:11:30 29 4
gpt4 key购买 nike

tl; dr: 安装了带有 cabal 沙箱的库,ghci 仍然提示该库丢失

我有一个目录,我正在开发一些 Haskell 的东西。这曾经在另一台带有 ghc 7.6 的计算机上工作正常,但现在我正在另一台带有 ghc 7.8.2 的计算机上工作(我不知道版本是否重要)我收到如下错误:

Prelude> :l Interpreter.hs

Parser.hs:9:8: Could not find module ‘Text.ParserCombinators.Parsec’ Perhaps you meant Text.ParserCombinators.ReadPrec (from base) Text.ParserCombinators.ReadP (from base) Use -v to see a list of the files searched for.



尝试从 ghci 加载文件时。这些文件位于 BASE/src/Lib 中,其中 BASE 是包含 LIB.cabal 和所有内容的目录。所以我认为 cabal 有问题。为了避免可怕的“ cabal hell ”,我在项目中创建了一个沙箱( cabal sandbox init ),我以前没有使用过。然后我手动删除了其他与 cabal 相关的东西并做了 cabal init 。我做了 cabal install --dependencies-only ,但实际上并没有安装任何东西(我猜是因为 --dependencies-only?我对全局安装过于偏执而无法使用常规 cabal 安装)。因此,我尝试将内容手动添加到我的 .cabal 文件中(您应该这样做吗?),即:

build-depends:

base >=4.7 && <4.8,

containers >=0.5 && <0.6,

--

parsec == 3.1.* -- THIS is the line I added


现在我做了 cabal install --dependencies-only 。瞧,实际上已经安装了东西,特别是:

[21 of 25] Compiling Text.Parsec ( Text/Parsec.hs, dist/dist-sandbox-a2fe5095/build /Text/Parsec.o )

...

In-place registering parsec-3.1.5... Installing library in /home/PATHTODIR/Stack Lang/.cabal-sandbox/lib/x86_64-linux-ghc-7.8.2/parsec-3.1.5 Registering parsec-3.1.5... Installed parsec-3.1.5



所以我尝试在 ghci 中加载相同的文件,产生相同的错误。请注意,问题是 Text.ParserCombinators.Parsec,根据我运行 cabal install --dependencies-only 的时间,它似乎安装得很好。这是我使用 ghc -v Interpreter.hs 得到的输出:

Glasgow Haskell Compiler, Version 7.8.2, stage 2 booted by GHC version 7.4.1

Using binary package database: /opt/ghc/7.8.2/lib/ghc-7.8.2/package.conf.d/package.cache

wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-948744e1f99cc8bcc7c7d3ba60c7c2d8

wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-dc47f6b546fc171f67a7f7d311684a99

wired-in package base mapped to base-4.7.0.0-018311399e3b6350d5be3a16b144df9b

wired-in package rts mapped to builtin_rts

wired-in package template-haskell mapped to template-haskell-2.9.0.0-

dcc8c210fb02937e104bc1784d7b0f06

wired-in package dph-seq not found.

wired-in package dph-par not found.

Hsc static flags:

wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-948744e1f99cc8bcc7c7d3ba60c7c2d8

wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-

dc47f6b546fc171f67a7f7d311684a99

wired-in package base mapped to base-4.7.0.0-018311399e3b6350d5be3a16b144df9b

wired-in package rts mapped to builtin_rts

wired-in package template-haskell mapped to template-haskell-2.9.0.0-

dcc8c210fb02937e104bc1784d7b0f06

wired-in package dph-seq not found.

wired-in package dph-par not found.

* Chasing dependencies:

Chasing modules from: *Interpreter.hs

Parser.hs:9:8: Could not find module ‘Text.ParserCombinators.Parsec’ Perhaps you meant Text.ParserCombinators.ReadPrec (from base) Text.ParserCombinators.ReadP (from base) Locations searched: Text/ParserCombinators/Parsec.hs Text/ParserCombinators/Parsec.lhs

Parser.hs:10:18: Could not find module ‘Text.Parsec.Token’ Locations searched: Text/Parsec/Token.hs Text/Parsec/Token.lhs

Interpreter.hs:11:8: Could not find module ‘Control.Monad.Error’ Perhaps you meant Control.Monad.Fix (from base) Control.Monad.ST (from base) Control.Monad.Zip (from base) Locations searched: Control/Monad/Error.hs Control/Monad/Error.lhs

Interpreter.hs:15:8: Could not find module ‘Text.ParserCombinators.Parsec.Error’ Locations searched: Text/ParserCombinators/Parsec/Error.hs Text/ParserCombinators/Parsec/Error.lhs * Deleting temp files: Deleting: * Deleting temp dirs: Deleting:

最佳答案

ghc/ghci 不会自动识别沙箱。默认情况下,它们只查看全局和用户包数据库。

要么使用 cabal repl 来启动 ghci,要么遵循我的文章 cabal sandbox tips 中的食谱。两者都可能需要最近(1.18 之后)的 cabal 。

关于haskell - 在沙箱中安装了 parsec,但在 ghci 中尝试加载文件时找不到库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23120611/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com