Having a hierarchy
open FSharp.Data.UnitSystems.SI.UnitSymbols
type Vector2D<[<Measure>] 'u>(x: float<'u>, y: float<'u>) =
member val Abs =
let squared = float (x*x+y*y)
LanguagePrimitives.FloatWithMeasure<'u> (Math.Sqrt squared)
type R2D =
inherit Vector2D<m>(x, y)
member val X = x
member val Y = y
type V2D(vx, vy) =
inherit Vector2D<m/s>(vx, vy)
member val Vx = vx
member val Vy = vy
type A2D(ax, ay) =
inherit Vector2D<m/s^2>(ax, ay)
member val Ax = ax
member val Ay = ay
I would like to define global inline operator (+) (l:^v) (r:^v) where ^v would be required to inherit from Vector2D, have some unit of measure float<'u> and have constructor with two parameters of type float<'u>.
Is it possible?