I have a function in Haskell which returns me the successor of a card. I know how to access the card, using list comprehension, but not quite sure how to get the next card, so pos+1. Here is my code:
pCard :: Card->Deck->Card
pCard (K,C) _ = (A,S) --exception for last card
pCard crd pck = head [p | (pos,p) <- (zip [0..51] pck), crd==p]
Hint: use dropWhile (/= crd) pck to remove all the cards from the beginning until your card is found. Then, the first card remaining is crd. The one after that is the one you want.
Still, if pck is a deck in a standard order, looping over the whole deck to find the next card seems to be quite inefficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With