Hi,
I did a few mental steps without explaining them, so let me clarify this.
Object expressions in F# are really (currntly) intended only for implementing a single interface type, which means that the type of the expression is just this interface type. You cannot for example add new members, because the return type is the interface that you're impementing and there wouldn't be any (reasonable) way for accessing the members. I'm a bit surprised that the syntax allows implementing multiple interfaces, because as far as I know this isn't currently the intended use (but I think that it makes very good sense and that it would be nice to support this in the future by returning a type that implements both interfaces - this is probably a bit difficult to implement technicall in .NET, but I think it should be possible). So that's I think why it doesn't work without dynamic tests.
The restriction for classes is sometimes useful - for example let's say you have a base class A, class B inherited from A and some completely unrelated class C. When you have instances a, b and c the compiler will do the following:
a :?> B // allowed because B inherits from A so 'a' can be instance of B upcasted to type A
c :?> B // not allowed because instance of type C cannot contain a value that
// could be casted to B (because .NET supports single implementation inheritance)
However - these restrictons don't work well or inerface types, because a class can implement multiple intrfaces.
Tomas Petricek (
Blog), C# MVP
My book:
Real-world Functional Programming in .NET