
28 Nov
2008
28 Nov
'08
6:59 p.m.
Torsten Otto wrote:
We have this working:
import System.Random
main = do randomNumber <- randomRIO (1::Int,2) print (randomAnswer randomNumber)
randomAnswer r | (r == 1) = "Nope!" | (r == 2) = "Absolutely!" | otherwise = "Error!"
could be more concisely
randomAnswer r = ["Nope!", "Absolutely!"] !! r and 0-based rather than 1-based: main = do randomNumber <- randomRIO (0::Int,1) print (randomAnswer randomNumber)
for example, although it worked fine as-is, and it's possible to abstract more nicely than what I showed here too -Isaac