
17 Nov
2010
17 Nov
'10
4:48 p.m.
aditya siram
Does this help? http://www.haskell.org/haskellwiki/99_questions/Solutions/24 -deech
Indeed it does, thank you deech. For the benefit of anyone who googles this, here's a solution that works. import "mtl" Control.Monad.State import System.Random -- | Choose an element at random from a list and return the element and its index randomListSelection :: [a] -> IO (Int, a) randomListSelection xs = do i <- randomRIO (0,(length xs)-1) return (i, xs !! i) chooseCreatur :: IO (Int, [Char]) chooseCreatur = randomListSelection ["cat", "dog", "lion", "mouse"]