Edited at

randomの動かし方

More than 1 year has passed since last update.

すごいH本を写経していて9.6ランダム性の部分がGHC7.8.3では動かなかった

Prelude> random (mkStdGen 100) :: (Int, StdGen)

<interactive>:6:1: Not in scope: ‘random’

<interactive>:6:9: Not in scope: ‘mkStdGen’

<interactive>:6:32:
Not in scope: type constructor or class ‘StdGen’

importしてみてもダメだった

Prelude> import System.Random

<no location info>:
Could not find module ‘System.Random’
It is not a module in the current program, or in any known package.
Prelude> import System.Random

<no location info>:
Could not find module ‘System.Random’
It is not a module in the current program, or in any known package.

どうやらrandomというパッケージを入れれば良いみたい

$ brew install cabal-install

$ cabal update
$ cabal install random

無事動いた

relude> import System.Random                                                                               

Prelude System.Random> random (mkStdGen 100) :: (Int, StdGen)
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package old-locale-1.0.0.6 ... linking ... done.
Loading package time-1.4.2 ... linking ... done.
Loading package random-1.1 ... linking ... done.
(-3633736515773289454,693699796 2103410263)