3

这是一个猜测数字代码。当我运行它时,我收到一个错误:找不到模块“随机”。我应该怎么办 ?

module Main where 

import IO
import Random

main = do 
       hSetBuffering stdin LineBuffering
       num <- randomRIO (1::Int, 100)
       putStrLn "I'm thinking of a number between 1 and 100"
       doGuessing num = do
           putStrLn "Enter your guess:"
           guess <- getLine
           let guessNum = read guess
           if guessNum < num
              then do putStrLn "Too Low!"
                   doGuessing num
           else if guessNum > num
              then do putStrLn "Too High"
                   doGuessing num
           else do putStrLn "You Win!"
4

2 回答 2

5

你应该使用

import System.IO
import System.Random

反而。

于 2012-09-28T09:27:32.857 回答
1

安装random包。最简单的方法是使用cabal

cabal install random
于 2012-09-28T09:18:32.277 回答