I'm trying to write a recursive function for building a specialized card deck. The first parameter, numOfCards is supposed to be the number of cards in the deck. The sourceDeck is a list of possible cards that can be used to build the deck and the currentDeck is my accumulator, which results in the final list of cards.
However, the problem I have is that when I send in a number value for numOfCards it gets set to 0 in the match statement. Or at least that's how it looks. I tried stepping through with the debugger, and when I enter the function, the value is correct. As soon as I start executing the match, however, it suddenly becomes 0, both if I hover over the value in the match and over the value in the parameters (which is at least consistent).
As such, the match triggers on 0 and just returns the empty currentDeck, rather than iterating.
Any tips on this one? Probably something simple, but I'm stumped. :)
let rec buildDungeon (numOfCards, sourceDeck : List<Card>, currentDeck : List<Card>) =
match currentDeck.Length with
| numOfCards -> currentDeck
| _ -> buildDungeon (numOfCards, sourceDeck, newCard(sourceDeck)::currentDeck)