In the following snippet I'm trying to extract the recid contained in a nested tuple which forms a dict key. The nested tuple format is (Int32, (boolean, boolean)) -
I'm looking for the value of the Int32 item (which is actually the Row ID for a db record).
In the match code below I'm trying to add the recid to a list, but first I am casting to the object to an integer.
However this produces the following error - not sure why?
Error:
This runtime coercion or type test from type 'a to int32
involves an indeterminate type based on information prior to this program point.
Runtime type tests are not allowed on some types. Further type annotations are needed.
The dictionary being referenced here is defined as:
// Create Dict
let rdict = new Dictionary<_,_>()
// Add elements
rdict.Add( (x.["PatientID"],(true,true) ),ldiff)
// Extract Dict items
let reclist = new ResizeArray<int32>()
for KeyValue(k,v) in rdict do
match k with
| ((recid,(true,true)) ->
printfn "Found a matching Record: %A " recid; // <- prints correct result
let n = (recid:?> int32) // <- coercion error
reclist.Add(n)
rdict.Add( (x.["PatientID"],(true,true) )has a mismatched number of opening and closing parenthesis. What are theDictionary's key and value types? Isint*(bool*bool)intended to be the key type only, or isintthe key type andbool*boolthe value type? Also, what is the actual type ofx.["PatientID"]? Does that return anintor a boxedint(i.e.,objwhich can be cast toint)? - ildjarnrdictintoreclistif their accompanyingboolpair istrue, trueand not any other combination? - ildjarnprintfnhandlesrecidcorrectly because you're using%Aas the format specifier, which works with any and every type; I suspect it would fail if you used%dfor the format specifier instead, which means thatx.["PatientID"]is in fact not returning anint. Assuming you're using Visual Studio, can't you just mouse overrdictand look at the type in the tooltip? - ildjarn