if I want to define a extension method for float array like standard deviation, would it be better to use module extension on Array module or extension on type float[]?
like :
module Array =
let std (arr: float[]) = ...
or
type float ``[]`` with
member this.std = ...
If I do type extension as the latter, would the std be only calculated once or every time it is used?
And, what is the right format for the latter, apprently type float ``[]`` with does not comile… thanks.
In this case, you can’t define a type extension so the issue is moot – you must use an extension of the
Arraymodule. The reason that you can’t define a type extension is that in F#, type extensions must exactly mirror type definitions, so you can define a type extension on the generic'a listtype, for instance, but not on the constructed typestring list. Similarly, you could define an extension method on the (simulated) generic array typebut not on the constructed array type
This behavior is different than C#, where it is possible to write extension methods on constructed generic types.