Can I have a class with one member either be float array or array of float array like
type testArr(data: float[],...) =
member x.data = data
member x.others = ...
new( data: float[][],...) = ???
I tried to define
type Value = Value1D of float[] | Value2D of float[][], then define type testArr(data: Value,... ), but I then need to rewrite a lot of code for type Value to repeat the array type methods like .Item etc. Alternatively, How do I define type Value inherited from 'a[] but limit the elment type 'a to be float or float[] only?
I’m not entirely sure why would you need this, but you can define a
TestArrclass with private constructor and add two static methods to create the two types (float[]andfloat[][]) that you want to allow:Using an array of arrays always, but with just a single element for the 1D scenario as suggested by Gabe in a comment sounds like a good and simpler alternative.