Given the following code:
static member private getIntValue (_map:Map<string, int>) (_key:string) =
if (_map.ContainsKey _key) then
_map.[_key], _map
else
let i = doSomething ()
i, if i > 0 then _map.Add (_key, i) else _map
static member private getDataFn<'T> (_getFn:Map<string, 'T> -> string -> 'T * Map<string, 'T>) =
let dataMap = ref Map.empty
fun _key ->
let value, updatedMap = _getFn !dataMap _key
dataMap := updatedMap
value
static member getIndexNumber = getDataFn<int> getIntValue
... the value of the dataMap reference cell in the first line of the function definition (i.e. fun _key -> ...) of getDataFn<'T> is always empty (i.e. dataMap.Count = 0), no matter how many times I call getIndexNumber.
Obviously, I'm expecting dataMap to be updated whenever a non-existent key is passed to getIndexNumber, but this isn't happening. An empty Map is being passed to getIntValue every time.
Why is this happening?
(P.S. I know that I could just use a Dictionary, that's beside the point.)