I get the result of some calculations in the form of 'a option when 'a :> IBaseType . There is a tree of types derived from IBaseType , and I really donβt know which type is this, but whatβs important is that it is an option of a specific derived, and not a base type. Therefore, I want to increase it to the IBaseType option in order to process it further. Since the variant is a generic type, it cannot be executed directly (in F #), and I need to do the listing inside Option.map. Nothing complicated, the output type works as expected ...
an intermediate cast option is also allowed as expected ...
until the function is complete. At this point, for some reason, type inference decided that the original option should already be of type IBaseType option : 
The intermediate type was already resolved earlier, why did he decide to reassign the deduced type op ? Of course, this leads to runtime exceptions. It looks like a compiler error, but the basic rule is that there are no errors in the compiler.
So, in the end, it sounds very silly: I have no idea how to simply simplify a simple option. To make the image clearer: processResult takes an IBaseType option as an argument. And here is the source of the problematic function:
(fun (x: obj) -> let op = x :?> _ option let upcastOp = op |> Option.map (fun y -> y :> IBaseType) upcastOp |> processResult)
Any ideas how to deal with this?
source share