[英]Can't load Graphics.Gloss in Haskell
I wanted to play around with Pong.hs . 我想和Pong.hs一起玩。 I downloaded the
.hs
file, but when I opened it in Sublime Text (with the Haskell plugin) I was told that Graphics.Gloss
and Graphics.Gloss.Interface.Pure.Game
were missing. 我下载了
.hs
文件,但是当我在Sublime Text(带有Haskell插件)中打开它时,被告知Graphics.Gloss
和Graphics.Gloss.Interface.Pure.Game
丢失了。
> cabal install Graphics.Gloss
couldn't find Graphics.Gloss
. 找不到
Graphics.Gloss
。 Hoogle found it for me. Hoogle为我找到了它。 One of the comments in the file mentioned compiling
Gloss
. 文件中的注释之一提到了编译
Gloss
。 So I tried 所以我尝试了
> cabal install Gloss
which succeeded -- although I don't understand why. 成功了-尽管我不明白为什么。 The Sublime Text plugin was also happy.
Sublime Text插件也很高兴。 But when I tried to load the code into WinGHCi, I got
但是当我尝试将代码加载到WinGHCi时,我得到了
Pong.hs:22:1: error:
Failed to load interface for ‘Graphics.Gloss’
Use -v to see a list of the files searched for.
Pong.hs:23:1: error:
Failed to load interface for ‘Graphics.Gloss.Interface.Pure.Game’
Use -v to see a list of the files searched for.
I'd appreciate suggestions about what to try next. 非常感谢您提出下一步建议。
Thanks. 谢谢。
First, some background: Graphics.Gloss
is the name of a module -- a collection of named code snippets. 首先,了解一些背景信息:
Graphics.Gloss
是模块的名称-命名代码段的集合。 gloss
is the name of a package -- a collection of modules. gloss
是包的名称-模块的集合。 cabal install
accepts a package name and installs that package into a package database -- a collection of packages. cabal install
接受软件包名称,并将该软件包安装到软件包数据库(软件包的集合)中。
Now we have the vocabulary we need to discuss what you observed, and how you can make progress. 现在我们有了词汇,需要讨论您观察到的内容以及如何取得进步。
cabal install Graphics.Gloss
couldn't findGraphics.Gloss
cabal install Graphics.Gloss
找不到Graphics.Gloss
Right, Graphics.Gloss
is a module, not a package. 正确,
Graphics.Gloss
是一个模块,而不是一个包。 The gloss
package provides that module. gloss
包装提供了该模块。 I don't know of a reliable tool for mapping module names to the packages that provide them, but Hoogle and Hayoo will both tell you the package name associated with any of their search results. 我不知道将模块名称映射到提供模块名称的可靠工具,但是Hoogle和Hayoo都会告诉您与任何搜索结果相关的软件包名称。 (I don't class them as "reliable" because they index only a subset of Hackage.)
(我不将它们归类为“可靠”,因为它们仅索引了一部分Hackage。)
cabal install Gloss
succeededcabal install Gloss
成功
Although the package is named gloss
and not Gloss
, cabal install
attempts to Do The Right Thing, installing a surrogate package if it differs only in case. 尽管该软件包的名称是
gloss
而不是Gloss
,但cabal install
尝试执行“正确的事情”,但仅在情况不同时安装替代软件包。
when I tried to load the code into WinGHCi, I got [an error]
当我尝试将代码加载到WinGHCi时,出现了[错误]
I would bet that Sublime Text and WinGHCi are using different package databases; 我敢打赌Sublime Text和WinGHCi使用不同的软件包数据库; for example, perhaps you are using a cabal sandbox and Sublime Text has picked that up.
例如,也许您使用的是阴谋集团沙箱,而Sublime Text已将其选中。 You could try running these two commands and comparing their output:
您可以尝试运行以下两个命令并比较它们的输出:
cabal sandbox hc-pkg list gloss
ghc-pkg list gloss
Note that the former will behave differently when run from different directories and in different environments, so take care to run it using the same steps you used to run cabal install Gloss
! 请注意,从不同目录和不同环境运行时,前者的行为会有所不同,因此请谨慎使用与执行
cabal install Gloss
相同的步骤来运行它!
If you have installed gloss into a sandbox, the first command should show you the location of the package database associated with that sandbox and the version of the gloss library installed there. 如果已将光泽安装到沙箱中,则第一个命令应显示与该沙箱关联的软件包数据库的位置以及在其中安装的光泽库的版本。 The second should show no results.
第二个不应显示任何结果。 If that is the case, you can try running WinGHCi using an environment appropriate for the sandbox;
在这种情况下,您可以尝试使用适用于沙箱的环境运行WinGHCi。 for example, something like
例如,类似
cabal exec winghci
should do the trick (if winghci
is the command that starts WinGHCi -- no Windows box here, so I don't know for sure). 应该可以解决问题(如果
winghci
是启动WinGHCi的命令-这里没有Windows框,所以我不确定)。 Again, being in the right directory with the right environment variables set is important for this command to work, so make sure you run it following the same steps you did for running cabal install Gloss
and the previous package database query. 同样,在正确的目录中设置正确的环境变量对于此命令的工作很重要,因此请确保按照与执行
cabal install Gloss
和先前的软件包数据库查询相同的步骤运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.