无法加载在Haskell中使用标准库的文件 [英] Can not load a file that uses standard libraries in haskell
问题描述
我使用GHCI,通常可以加载我的文件.现在,我需要加载一个使用随机数的文件.我收到此错误.
Hi I use GHCI and can normally load my files. Now I need to load a file that uses random. I get this error.
Chatterbot.hs:3:1: error:
Could not find module ‘System.Random’
Use -v to see a list of the files searched for.
|
3 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
这很奇怪,因为它适用于我的朋友,我的朋友也刚刚安装了GHCI,除了我什么都没做.主要区别在于我在Windows上.我真的不明白这一点,并且尝试了一下谷歌搜索,许多人都在谈论堆栈,但这似乎很烦人,并且显然,如果没有它,我的朋友也可以使用.
This is very weird since it works for my friend who also have just installed GHCI and did nothing other than me. The main difference is that I am on windows. I really don t understand this and have tried googling a bit and many people speak about stack but it seems annoying and It obviously works for my friend without it.
预先感谢
编辑问题已解决.我需要更新cabal,然后随机运行cabal install,效果很好.谢谢大家的帮助!
EDIT problem solved. I needed to update cabal then I ran cabal install random and it worked well. Thanks everyone for the help!
推荐答案
如果使用的是 cabal-install > = 3.0(使用 cabal --version
进行检查),则可以创建一个空文件夹并
If you are using a version of cabal-install >= 3.0 (check with cabal --version
), then, instead of creating a cabal package, you can move to an empty folder and type:
cabal install --lib --package-env . random
这将创建一个 .文件夹中的ghc.environment 文件.在该文件夹中启动的 ghci
会话将对其进行拾取,并且将能够导入System.Random
.
This creates a .ghc.environment file in the folder. ghci
sessions started inside that folder will pick it up, and they will be able to import System.Random
.
如果该方法正常工作,则可能需要全局安装随机",以便任何ghci调用都可以使用它:
If that works correctly, you might want to install "random" globally so that any invocation of ghci can use it:
cabal install --lib random
这会创建/修改全局环境文件位于〜/.ghc/$ ARCH- $ OS- $ GHCVER/environments/default
.
这篇关于无法加载在Haskell中使用标准库的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!