I believe this is not possible, due to the way the (+) operator is defined. It delegates to a static implementation of either of the operand's classes. This mechanism can't use abstract methods because it happens at compile time (uses statically resolved type parameters).

You could redefine operator (+), but I don't recommend that. You could however define a new operator like this:

1
2
3
4
type IT =
   abstract Add : IT -> IT

let (+++) (lhs:IT) (rhs:IT) = lhs.Add rhs

And then implement the interface in a type:

1
2
3
4
5
6
 

type T() =
   interface IT with
      override x.Add other = new T() :> IT

This implementation is quite nonsensical, of course. It is actually difficult to implement Add in a meaningfull way, because the method does't know anything about the "other" argument. But maybe this approach is useful in your application...

Example usage of the (+++) operator:

1
2
3
4
5
let it = new T() :> IT
let t = new T()

let r = it +++ t
By on 6/4/2011 5:31 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper