1
Vote

Structural Typing

description

The proposed feature would involve defining the intended structure of a given type-parameter through defining method/property/indexer/event/constructor signatures on the type-parameter.  To further ease description of similar structures, a variation to interfaces will be proposed which will be defined as 'implicit' interfaces.  Such interfaces need to be defined explicitly as such, and can only inherit from other interfaces of a like kind.
 
The functional description of how such a thing would work would be the implicit interfaces have two definitions, one describes the structure, the 'how', the other describes the dispatching mechanism used to relay the messages (essentially two interfaces would be created.)
 
Generic type parameters which use implicit interfaces will utilize their functionality through the dispatch interface, using an cache that describes the generic-type closure of a given set of types as the key for retrieval.  Once retrieved the relative instance will hold a static reference to that dispatch to expedite future accesses.
 
The structure of this feature will likely change as it matures.
 
One major difference between the implicit interfaces and the direct structural typing declarations is the interfaces cannot define constructor requirements.

comments