私はHaskell(およびプログラミング)にまったく慣れていません。私の課題は、1 組のカード (別名 52 枚) を返す関数を定義することです。コードの横のメモに私の思考プロセスを含めようとしています。
-- 私が定義した値
data Suit = Club | Diamond | Heart | Spade deriving (Show, Enum)
data Value = Two | Three | Four | Five | Six | Seven
| Eight | Nine | Ten | Jack | Queen
| King | Ace deriving (Show, Enum)
type Card = (Suit, Value) -- A card must have a suit and a value
type Deck = [Card] -- A deck consists of a list of cards
fullDeck :: Deck -- My function is supposed to consist of a deck
fullDeck = [(suit, value) | suit <- [Club..Spade], value <- [Two..Ace]] -- Tried my luck using ''list comprehensions''. Is it necessary to type [Club..Spade] or does it work for just [Club..] as well?
コードが読み込まれません。私が得ているエラー:
beginner.hs:11:62: error:
A section must be enclosed in parentheses thus: (Two.. Ace)
|
11 | fullDeck = [(suit, value) | suit <- [Club..Spade], value <- [Two..Ace]]
どのように解決しようとしても、いくつかの新しいエラーが表示されるため、明らかに、特定できないいくつかの大きな失敗をしています。
また、現時点で私のリストは無限の量で構成されているため、デッキに 52 枚のカードしかないようにする方法にも興味があります。