[Haskell-cafe] Occurs check error, help!

Yuras Shumovich shumovichy at gmail.com
Sat Mar 20 15:26:18 EDT 2010


Hi,

> shuffle :: int -> [a] -> [a]
> shuffle i [cards] = ...
So 'cards' is of type 'a' :
  cards :: a

> ... = (cards!!i)
So 'cards' is a list of something:
  cards :: [b]

> ... = (cards!!i) + ...
(+) :: b -> b -> b,
the result of the 'shuffle' should be of type [a], so
  b :: [a],
  cards :: [[a]]


2010/3/20 boblettoj <boblettoj99 at msn.com>:
>
> Hi i am writing a shuffle function which takes in a random number i and a
> list and then produces a jumbled up version of the list at the end. Here is
> what i have at the moment (i'm not sure if it works yet as it won't compile!
>
> --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))
>
>
> I get this error message when i try to compile:
>
> Occurs check: cannot construct the infinite type: a = [[a]]
>
> I'm very new to haskell so you'll have to excuse any ignorance!
> thanks
> --
> View this message in context: http://old.nabble.com/Occurs-check-error%2C-help%21-tp27966341p27966341.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