TYPES
Inheritance
4 min
shift supports single inherietence from any type of the same kind there are some restrictions which kinds can inherit from what structure structures records all inherited fields will be readonly interfaces record interfaces records library nothing as a consequence of a library actually being a value and not a type service interfaces services records interface interfaces enum nothing though a type alias to a enum union would let you combine the list of values together furthermore a type can subtype any number of interfaces this does require the interface is fully implemented that means any fields from the interface must match any declaration rules for the type's kind for example shift interface somefields { readonly int a;//fields take the default implementation } record myrecord somefields { string sometextdata; } it is ok for myrecord to subtype somefields since field a is readonly and a record this means any method taking somefields in will be constrained in its interface with field a the same way a record would be if it wasn't marked readonly or if a's type wasn't a record then the interface couldn't be implemented, and this wouldn't compile subtypes when a type inherits or implements an interface it becomes a subtype of that anywhere that constrains to a specific type, a subtype can alternatively be supplied which is to say type satisfaction for type safety is covariant shift interface a { string name; string tostring(); } structure foo a { string tostring() => $"honk honk i am {name}"; } structure bar foo { this() { name = "biggest honk" } } the subtype graph for this would look like graph td; bar >foo; foo >a; foo is a subtype of a so anywhere requiring an a, a foo can be supplied bar is a subtype of foo and by extension is also a subtype of everything foo is if you had a method or a variable requiring an a you could pass either a foo or bar variable in shift var ex = new foo(); var ex2 = new bar(); a ex3 = ex; a ex4;//throws an exception, interfaces cannot be instantiated console writeline(ex tostring());// "honk honk i am " console writelien(ex2 tostring());// "honk honk i am biggest honk"
