[Haskell-cafe] Occurs check error, help!

boblettoj boblettoj99 at msn.com
Sat Mar 20 15:39:00 EDT 2010


Ah yes, that makes sense now, however i have another problem, here is the
updated code:

--function used to shuffle cards 
--list equals random member of array plus the rest of the array
--i is randomly generated from range of length equal to that of cards.
shuffle :: Int -> [a] -> [a]
shuffle i [] = []
shuffle i cards = [(cards!!i) :
	(shuffle (randomR(0, ((length cards)-2)))
	(delete (cards!!i) cards))]

and the message:
cards.hs:32:11:
    Couldn't match expected type `Int'
           against inferred type `g -> (Int, g)'
    In the first argument of `shuffle', namely
        `(randomR (0, ((length cards) - 2)))'
    In the second argument of `(:)', namely
        `(shuffle
            (randomR (0, ((length cards) - 2))) (delete (cards !! i)
cards))'
    In the expression:
          (cards !! i)
        : (shuffle
             (randomR (0, ((length cards) - 2))) (delete (cards !! i)
cards))

Doesn't RandomR return an Int?
thanks
-- 
View this message in context: http://old.nabble.com/Occurs-check-error%2C-help%21-tp27966341p27967762.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list