Haskell: Can't import System.Random
我已通过此处的说明(即使用
1 | import System.Random |
引入了
1 | stack install random |
再次输入ghci之前。此命令产生了大量的输出,其中一部分与System.Random有关:
random> configure
random> Warning: random.cabal:15:2: Tabs used as indentation at 15:2, 16:2, 17:2
random> Configuring random-1.1...
random> build
random> Preprocessing library for random-1.1..
random> Building library for random-1.1..
random> [1 of 1] Compiling System.Random
random>
random> /private/var/folders/bg/zjbyc9fj64d5kr98_x5bfjtm0000gn/T/stack946/random-1.1/System/Random.hs:43:1: warning: [-Wtabs]
random> Tab character found here, and in 74 further locations.
random> Please use spaces instead.
random> |
random> 43 | (
random> | ^^^^^^^^
现在我有一些问题:
(1)使用此堆栈安装命令究竟在做什么?我知道在不了解应该执行的命令的情况下执行命令是有风险的,但事实是,这正是我所做的。我的猜测是,这正在获取一些库(类似于Ruby中的Gems或Perl中的CPAN)并将它们添加到Haskell实现中。但是,如果这些是"官方"库,为什么我会收到语法错误?我是否应该在已下载的源上运行
(2)这真的是将System.Random引入安装的官方方法,还是有一种更好的方法来获得Random模块?我希望这种模块已经像许多其他模块一样已包含在发行版中。
(3)现在我该怎么做才能获得随机数?因为我仍然收到找不到模块的错误(如果随机库的源代码有语法错误,这并不奇怪)
执行以下两个步骤以安装
1 2 | brew install haskell-stack stack ghci --package random |
1 2 3 4 5 | 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的精选软件包集,而