隐藏来自GHCi的随机版本 [英] Hiding versions of random from GHCi
问题描述
我正在使用 newsynth
包,并且遇到了一个错误,我开始怀疑它与整个夏天的更新 random-1.2.0
有关.( newsynth
的最新更新时间为2019年末, random-1.2.0
于6月发布.此后,我一直运行 cabal update
,这就是为什么两者似乎都安装的原因.)这是我在GHCi中运行的代码:
I am working with the newsynth
package and am running into a bug that I am starting to suspect has to do with the update random-1.2.0
over the summer (newsynth
was last updated in late 2019, and random-1.2.0
came out in June. I have run cabal update
since then, which is why both seem to be installed.) Here is the code that I ran in GHCi:
λ> import System.Random
λ> import Quantum.Synthesis.Ring
λ> import Quantum.Synthesis.Diophantine
λ> g <- getStdGen
λ> diophantine g (RootTwo 5 0)
<interactive>:5:1: error:
• No instance for (random-1.1:System.Random.RandomGen StdGen)
arising from a use of ‘diophantine’
There are instances for similar types:
instance random-1.1:System.Random.RandomGen
random-1.1:System.Random.StdGen
-- Defined in ‘random-1.1:System.Random’
• In the expression: diophantine g (RootTwo 5 0)
In an equation for ‘it’: it = diophantine g (RootTwo 5 0)
正如在另一篇SO帖子中向我建议的那样,我尝试从GHCi隐藏 random
的另一个副本.我跑了
As was suggested to me in another SO post, I tried hiding the other copy of random
from GHCi. I ran
$ ghc-pkg --global --package-db ~/.cabal/store/ghc-8.8.3/package.db list random
~/.ghcup/ghc/8.8.3/lib/ghc-8.8.3/package.conf.d
(no packages)
~/.cabal/store/ghc-8.8.3/package.db
random-1.1
random-1.2.0
所以我尝试了 $ ghc-pkg --global --package-db〜/.cabal/store/ghc-8.8.3/package.db隐藏random-1.2.0
.但是,当错误仍然存在时,我也尝试了 $ ghc-pkg --global --package-db〜/.cabal/store/ghc-8.8.3/package.db hide random-1.1
(只是为了确保 hide
达到了我的预期),但莫名其妙地发现,在GHCi中(即使在重新启动Terminal之后)我也可以运行λ>.尽管隐藏了
.我会以错误的方式隐藏包裹吗? random
的所有已知实例,但仍要导入System.Random
so I tried $ ghc-pkg --global --package-db ~/.cabal/store/ghc-8.8.3/package.db hide random-1.2.0
.
However, when the bug persisted, I also tried $ ghc-pkg --global --package-db ~/.cabal/store/ghc-8.8.3/package.db hide random-1.1
(just to make sure hide
did what I thought it would), yet inexplicably found that in GHCi (even after restarting Terminal) I was able to run λ> import System.Random
despite all known instances of random
being hidden. Am I hiding packages in the wrong way?
谢谢.
(前几天我问了一个相关的问题,但由于我认为这个问题有点不同,所以我认为将其分开是有意义的.如果不是这种情况,我可以更新另一篇文章.)
(I asked a somewhat related question the other day but since I think this issue is kinda different I thought it made sense be separate. If this is not the case I can update the other post.)
推荐答案
当您要管理软件包时,请使用cabal或stack.但首先,重置为干净状态:
Use cabal or stack when you want to manage packages. But first, reset to clean state:
rm -rf ~/.ghc ~/.cabal
cabal update
cabal v2-repl -b newsynth
这将使您进入GHCi会话并获得所需的软件包.
This will get you into a GHCi session with the desired package available.
这篇关于隐藏来自GHCi的随机版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!