I need to make an instance of arbitrary on my Haskell program, I'm creating a deck of cards (which is of type deck), and deck is a list of Cards, in order to make a new deck the program uses a mkStdGen and a number to prompt a seed, in order to randomize the new deck.
This deck needs to have an instance of arbitrary to pass the QuickTest property tests.
Here's some code
data Carta = C (Valor,Naipe) deriving (Eq,Ord)
instance Show Carta where
show (C (v,n)) =show v ++ show n
data Baralho = B [Carta]
instance Show Baralho where
show (B []) = ""
show (B [c]) = show c
show (B (c:cs)) = show c ++ "," ++ show (B cs)
type Mao = [Carta]
baralho40 :: Baralho
baralho40 = B [C (x,y)|y<-[Paus .. Espadas],x<-[As .. Rei]]
baralhar :: StdGen -> Baralho -> Baralho
baralhar g (B baralho) = B $ map snd $ sort $ zip (randomRs (1,(length baralho)^3) g) baralho