I am a beginner F# learner, currently trying some Lists actions within a BlackJack F# implementation.
I am trying to sum the elements of a list which I created as follows:
let cardsvalue (k: Cards): List<int> =
match k with
|Ace -> [1;11]
|Two -> [2]
|Three -> [3]
|Four -> [4]
|Five -> [5]
|Six -> [6]
|Seven -> [7]
|Eight -> [8]
|Nine -> [9]
|Ten | Jack | Queen | King -> [10]
type Cards is just a union of the cards Two to Nine , Ten to King and Ace.
So I need some kind of recursive function CardPoints which simply adds items from cardsvalue for example [Two; Three] = [5] or [Ace; Ace; Ace] = [3; 13; 23; 33] meaning all possible values of the Ace. I have tried several common ways of getting the sum but I always end up with type mismatch or not supporting operator error. For example
let rec CardPoints (cp: List<Cards>): List<int> =
match cp with
| head :: tail -> head + CardPoints tail
| [] -> 0
which is not accepting the + opperator.
I would love to see a possible implementation of this problem. Thank you for your time!