[Haskell-cafe] Re: Occurs check error, help!
TeXitoi
texitoi at texitoi.eu
Sun Mar 21 07:33:02 EDT 2010
boblettoj <boblettoj99 at msn.com> writes:
> newStdGen results in IO Ints whereas i need normal Ints and it seems theres
> no easy way to convert them without a lot more knowledge of haskell. I have
> tried using a where clause instead of using do but this is giving me the
> occurs check error again!
>
> --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 (fst pair) (delete (cards!!i) cards)]
^ ^
You are trying to do a one element list of list of card. so, the
result of this line should be a [[b]] = [a] => a = [b]. Inside this
list, we cons (cards !! i (type b) with shuffle (type [a] = [[b]]).
problem : we try to conssomething of type b with something of type [a]
= [[b]], but
ghci> :t (:)
(:) :: a -> [a] -> [a]
so b should be [b]. And so on.
Just remove the brackets.
> where pair = randomR (0, 51) (mkStdGen 42)
It makes me remember jokes :
- http://xkcd.com/221/
- http://www.random.org/analysis/dilbert.jpg
> and the error:
> cards.hs:30:0:
> Occurs check: cannot construct the infinite type: a = [a]
> When generalising the type(s) for `shuffle'
> Failed, modules loaded: none.
>
> hmmm...
--
Guillaume Pinot http://www.irccyn.ec-nantes.fr/~pinot/
« Les grandes personnes ne comprennent jamais rien toutes seules, et
c'est fatigant, pour les enfants, de toujours leur donner des
explications... » -- Antoine de Saint-Exupéry, Le Petit Prince
() ASCII ribbon campaign -- Against HTML e-mail
/\ http://www.asciiribbon.org -- Against proprietary attachments
More information about the Haskell-Cafe
mailing list