In fact, it is possible. There is a way to extend binary operators using a single and little-known ternary operator ?<- . Therefore, in your case, you can try the following:
type SumPoint3d = SumPoint3d with static member (?<-) (p:Point3d, SumPoint3d, t ) = Point3d(pX + t , pY + t , pZ + t ) static member (?<-) (t , SumPoint3d, p:Point3d) = Point3d(pX + t , pY + t , pZ + t ) static member (?<-) (p:Point3d, SumPoint3d, t:Point3d) = Point3d(pX + tX, pY + tY, pZ + tZ) static member inline (?<-) (a , SumPoint3d, b ) = a + b type ProdPoint3d = ProdPoint3d with static member (?<-) (p:Point3d, ProdPoint3d, t ) = Point3d(pX * t, pY * t, pZ * t) static member (?<-) (t , ProdPoint3d, p:Point3d) = Point3d(pX * t, pY * t, pZ * t) static member inline (?<-) (a , ProdPoint3d, b ) = a * b let inline ( + ) ab = a ? (SumPoint3d ) <- b let inline ( * ) ab = a ? (ProdPoint3d) <- b let a=Point3d (1.,2.,3.) let b=1.0
Now you can try:
> let c=a * b ;; val c : Point3d = Point3d (1.0,2.0,3.0) > 2 * 3 ;; val it : int = 6
Gustavo Nov 30 '11 at 13:45 2011-11-30 13:45
source share