I have a class in my application - for simplicity, suppose it is defined as follows:
type baseType() = member this.A = 5.
In addition, I have many functions that take objects of this type as an argument. Moreover, some of them take an array of this type:
let myFun (xArr : baseType[]) =
Now I realized that it would be nice to have another class that comes from "baseType". eg:.
type inhType() = inherit baseType() member this.B = 8.
However, I cannot use arrays of the inherited type with functions such as "myFun"
let baseArr = [| baseType() |] let inhArr = [| inhType() |] myFun baseArr myFun inhArr
which would be "nice to have." Is there an easy way to reuse my functions without making so many changes?
I assume that one solution is to display my array using, for example, the function (fun (d: inhType) -> d:> baseType), but I'm wondering if there is anything else.
source share