module FSharp=
let Point2d (x,y)= Point2d(x,y)
let Point3d (x,y,z)= Point3d(x,y,z)
type NXOpen.Point3d with
static member (*) (p:Point3d,t:float)= Point3d(p.X*t,p.Y*t,p.Z*t)
static member (*) (t:float,p:Point3d)= Point3d(p.X*t,p.Y*t,p.Z*t)
static member (+) (p:Point3d,t:float)= Point3d(p.X+t,p.Y+t,p.Z+t)
static member (+) (t:float,p:Point3d)= Point3d(p.X+t,p.Y+t,p.Z+t)
static member (+) (p:Point3d,t:Point3d)= Point3d(p.X+t.X,p.Y+t.Y,p.Z+t.Z)
let a=Point3d (1.,2.,3.)
let b=1.0
let c=a * b//error
錯誤15:類型 '浮動' 不匹配的類型
'三維點' E:\工作\擴展-RW \ VS \擴展\ NXOpen.Extension.FSharp \ Module1.fs 18 13 NXOpen .Extension.FSharp無法在F#中擴展運算符?
我想擴展Point3d方法,一些新的操作符。但它並沒有超過。
等一下,這不會破壞常規的'*'運算符嗎? 'inline'-magic-ness允許具有相同名稱的多個函數,並且方法重載? – Alxandr
@Alxandr是的,三元運算符被重載,'''''運算符被重定向到三元,所以它也會被重載。通過將任何特定的簽名或默認值與調用常規「*」操作符的泛型簽名進行匹配,在呼叫站點解析超載。 – Gustavo