[Haskell-cafe] Occurs check error, help!
Yuras Shumovich
shumovichy at gmail.com
Sat Mar 20 15:50:26 EDT 2010
2010/3/20 boblettoj <boblettoj99 at msn.com>:
>
> 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?
No, see docs
http://haskell.org/hoogle/?hoogle=randomR
> 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.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list