[Haskell-cafe] Occurs check error, help!

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Sat Mar 20 18:46:43 EDT 2010

boblettoj <boblettoj99 at msn.com> writes:

> Yes sorry, that line should be indented, now it gives me a bigger error :(
> What that line is trying to achieve is return a list where the first element
> is the card at the given random number in the first list and the rest of the
> list should be fed back in to shuffle along with a new random number.
> shuffle :: Int -> [a] -> [a]
> shuffle i [] = []
> shuffle i cards = do
> 	gen <- mkStdGen
> 	return ([(cards!!i) : (shuffle (randomR (0, ((length cards)-2)) gen)
> (delete (cards!!i) cards))])

First of all, why are you using a do block?

Secondly, mkStdGen :: Int -> StdGen : you need to provide it with a
number and it doesn't return a monadic value, so you can't use <- with

Thirdly, have a look at randoms and randomRs.

Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list