我正在使用堆栈ghci版本8在Ubuntu 16.04上工作。我想在Haskell中导入System.Random,但似乎遇到麻烦,可能涉及Cabal。我在该网站上看到过类似的帖子,但他们通常说这是因为版本较旧,但我使用的是版本8。
我得到了错误:
Failed to load interface for ‘System.Random’
Use -v to see a list of the files searched for.
告诉我我在System.Random中遇到问题。在线查看时,我发现需要首先安装Cabal。
当我打字
Cabal --version
我懂了
cabal-install version 1.22.6.0
using version 1.22.5.0 of the Cabal library
告诉我我已经拥有了。所以当我尝试更新
sudo apt-get install cabal-install cabal update
我懂了
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package cabal
E: Unable to locate package update
这很奇怪。如果我忽略它并尝试通过任意方式随机安装
cabal install random
我懂了
Resolving dependencies...
All the requested packages are already installed:
random-1.1
Use --reinstall if you want to reinstall anyway.
所以看来我也有随便的东西。但是我无法使用
import System.Random
命令。
编辑:看来我有堆栈ghci版本8.0.1和ghci版本7.10.3。System.random在ghci中加载,但不在堆栈ghci中加载。
当我尝试在堆栈中加载文件时,也会得到以下信息。进入
stack ghci R.hs
我懂了
Warning: Couldn't find a component for file target /home/aa/workspace/share/haskell/chenw/hw4/R.hs. Attempting to load anyway.
Configuring GHCi with the following packages:
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/aa/.ghc/ghci.conf
Loaded GHCi configuration from /tmp/ghci19674/ghci-script
这是否意味着我的堆栈安装有问题?
如果您想使用stack
并假设自己可以使用,stack
则无需通过进行任何安装apt-get
。
首先,更新您的 stack
stack update
确保您的软件包具有正确的resolver
版本号
stack ghci <source.hs>
。检查~/.stack/global-project/stack.yaml
。stack
,即。stack new <project>
,stack build
。检查项目的stack.yamlstack
全局使用(任何地方)
stack install random
stack ghci
和使用GHCi:load <source.hs>
stack ghc <source.hs>
stack exec <executable_name>
您可以使用强制堆栈使用特定的解析程序--resolver=
。
示例:使用最新的lts
$ stack --resolver=lts setup
$ stack --resolver=lts install random
$ stack --resolver=lts ghci
要stack
在项目目录(stack.yaml
存在)中使用,您无需手动安装软件包。stack
会在需要时为您安装它stack build
。但是你必须编辑<project.cabal>
build-depends: base >= 4.7 && < 5
, random
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句