Skip to content

Erased interfaces #106

Open
Open
@AnthonyDGreen

Description

@AnthonyDGreen

In #43 @Bill-McC suggested something pretty awesome to address scenario #135 that's been stuck in my mind. The sticking point we've had with "dynamic" interfaces/duck typing has been how to validate that the object being "casted" to has all of the required behaviors of a duck. Bill had the insight that the major benefit of duck typing isn't the error proofing but the tooling. With compile-time constraints you can get IntelliSense and other type checking. If we chuck the performance goal the feature becomes both simpler and more powerful, I think (and is it that much more dangerous than COM interop and NoPIA?).

In short, you'd declare such an interface normally but you'd be able to specify some sort of erasure pattern.

<Erased(DefaultErasure:=Erasure.MemberAccess)>
Interface IDuck
   Sub Quack()
End Interface

At design-time everything would behave as though this interface were real but during compilation the compiler would erase any use of members of the interface in some prescribed way. By default a late-bound access would be the most useful but we could also support erasing to a dictionary access to provide strongly-typed tooling over expando-objects or the XML axis properties. All the casting and stuff on the consuming side should probably be preserved.

F# has this feature called type providers where F# developers can write plugins to the compiler the generate types/objects on the fly often providing a typed view over untyped data from CSVs, databases, and web services. I think if you combined the ability to define erased interfaces with the proposed code-injectors feature you get many of the benefits of type providers without the complexity of forcing extenders to produce bound trees.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions