Haskell:无法导入System.Random [英] Haskell: Can't import System.Random

查看:467
本文介绍了Haskell:无法导入System.Random的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已通过此处找到的说明在MacOS Mojave上安装了Haskell,即使用命令.但是,

I have installed Haskell on MacOS Mojave via the instructions found here, i.e. using the stack command. However,

import System.Random

引入了ghci错误消息找不到模块"System.Random" .通过寻找解决方案,我遇到了有关Stackoverflow的讨论,我遵循了迈克尔·斯诺曼(Michael Snoyman)在那儿发布的建议,尝试使用该命令

brought in ghci the error message Could not find module ‘System.Random’. By searching for a solution, I came accross this discussion on Stackoverflow, and I followed the suggestion posted there by Michael Snoyman to try the command

stack install random

在再次输入ghci之前.该命令产生了大量的输出,其中一部分与System.Random有关:

before entering ghci again. This command produced tons of output, one part relating to System.Random :

随机>配置

random> configure

随机>警告:random.cabal:15:2:制表符用作15:2、16:2、17:2的缩进

random> Warning: random.cabal:15:2: Tabs used as indentation at 15:2, 16:2, 17:2

随机>配置random-1.1 ...

random> Configuring random-1.1...

随机>建立

随机>随机1.1预处理库..

random> Preprocessing library for random-1.1..

随机>建立随机1.1的库..

random> Building library for random-1.1..

随机> [1之1]正在编译System.Random

random> [1 of 1] Compiling System.Random

随机>

随机> /private/var/folders/bg/zjbyc9fj64d5kr98_x5bfjtm0000gn/T/stack946/random-1.1/System/Random.hs:43:1:警告:[-Wtabs]

random> /private/var/folders/bg/zjbyc9fj64d5kr98_x5bfjtm0000gn/T/stack946/random-1.1/System/Random.hs:43:1: warning: [-Wtabs]

随机>在此处以及其他74个位置中找到制表符.

random> Tab character found here, and in 74 further locations.

随机>请改用空格.

random> Please use spaces instead.

随机> |

随机> 43 | (

random> 43 | (

随机> | ^^^^^^^^^

random> | ^^^^^^^^

现在我有一些问题:

(1)这个 stack install 命令到底在做什么?我知道在不了解应该执行的命令的情况下执行命令是有风险的,但事实是,这正是我所做的.我的猜测是,这正在获取一些库(类似于Ruby中的Gems或Perl中的CPAN),并将它们添加到Haskell实现中.但是,如果这些是官方的",则不存在.库,为什么我会收到语法错误?我是否应该在已下载的源代码上运行expand来摆脱这些标签?

(1) What exactly was I doing with this stack install command? I know that it is risky to run a command without knowing well what it is supposed to do, but truth is this is exactly what I did. My guess is that this is fetching some libraries (similarly to Gems in Ruby or CPAN in Perl) and add them to the Haskell implementation. But if these are "official" libraries, why then do I get a syntax error? Am I supposed to run expand on the sources which had been downloaded, to get rid of the tabs?

(2)这真的是将System.Random引入安装的官方方法,还是有一种更好的方法来获得Random模块?我希望这种模块已经像许多其他模块一样已经包含在发行版中.

(2) Is this really the official way to get System.Random into the installation, or is there a better way to get the Random module? I would have expected that this kind of module is already included in the distribution, like many other modules are.

(3)现在我该怎么做才能获得随机数?因为我仍然收到找不到模块的错误(如果随机库的源代码有语法错误,这并不奇怪)

(3) What can I do now to get my Random numbers? Because I still get the error that the module can't be found (not surprisingly, if the source code of the random library has syntax errors)

推荐答案

执行以下两个步骤以安装stackSystem.Random

Do the following 2 steps to get stack and System.Random installed

brew install haskell-stack
stack ghci --package random

Configuring GHCi with the following packages:
GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /private/var/folders/5d/b7qfjxcd27v_3pgvdxzz1vr8nncyxt/T/haskell-stack-ghci/2a3bbd58/ghci-script
Prelude> import System.Random
Prelude System.Random>

stackage 是一组精选的hackage软件包,而stack是构建系统工具集.是的,它像CPAN一样,但不像Python的virtualenv那样是系统范围的.

stackage is a curated set of packages from hackage and stack is a build system toolset. Yes it's CPAN like but not system-wide, like a Python's virtualenv.

这篇关于Haskell:无法导入System.Random的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆