[Haskell-cafe] Occurs check error, help!
boblettoj
boblettoj99 at msn.com
Sat Mar 20 18:33:12 EDT 2010
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))])
I am now getting this error:
[1 of 1] Compiling Cards ( cards.hs, interpreted )
cards.hs:32:1:
Couldn't match expected type `[a]' against inferred type `Int -> b'
In a stmt of a 'do' expression: gen <- mkStdGen
In the expression:
do { gen <- mkStdGen;
return
([(cards !! i)
: (shuffle
(randomR (0, ((length cards) - 2)) gen)
(delete (cards !! i) cards))]) }
In the definition of `shuffle':
shuffle i cards
= do { gen <- mkStdGen;
return
([(cards !! i)
: (shuffle
(randomR (0, ((length cards) - 2)) gen)
(delete (cards !! i) cards))]) }
any ideas?
--
View this message in context: http://old.nabble.com/Occurs-check-error%2C-help%21-tp27966341p27972393.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe
mailing list