samedi 7 janvier 2017

Data.Random.Extras Usage

I'm trying to use a shuffle function from Data.Random.Extras package on the list of cards I have created. My code:

module Cards where

import Data.Random.Extras

data Suit = Clubs
             | Diamonds
             | Hearts
             | Spades
               deriving (Eq,Enum,Ord,Show,Bounded)

data Value =  Two
            | Three
            | Four
            | Five
            | Six
            | Seven
            | Eight
            | Nine
            | Ten
            | Jack
            | Queen
            | King
            | Ace
                deriving (Eq,Enum,Ord,Show,Bounded)

data Card = Card Value Suit
                deriving (Eq,Ord,Show)

type Deck = [Card]

-- Generate deck of cards
generateDeck :: Deck
generateDeck = [Card val suit | suit <- [Clubs .. Spades], val <- [Two .. Ace]]

-- Print deck of cards
printDeck :: Deck -> IO ()
printDeck deck = putStr (formatDeck deck)
  where
    formatDeck [] = []
    formatDeck (x:xs) = (show x) ++ "\n" ++ formatDeck xs

The problem is that when I'm trying to execute shuffle $ generateDeck on GHCi prompt I'm getting:

No instance for (Show (Data.RVar.RVar [Card]))
  arising from use of 'print'
Possible fix:
  Add an instance declaration for (Show (Data.RVar.RVar [Card]))
In a stmt of an interactive GHCi command: print it

I spent hours searching and trying to solve/understand this without any success. I would really appreciate your help.

Thank you.




Aucun commentaire:

Enregistrer un commentaire