Hmm, the is `type` the static type or the dynamic type, for languages where both apply?
ahoka•2mo ago
It’s a very confusing question. How can an evaluated expression’s result have multiple types?
suspended_state•2mo ago
I don't know what GP meant, but I can give an example of how I understand it (disregarding the spurious "the" in his comment): in a type system with sub-typing, your expression could be statically typed to return a certain type, and at runtime return any of its sub-types.
For instance, in typescript you could ascribe an expression with the type Any, yet the actual runtime type will not be Any, it will be any concrete type.
In object oriented languages, you may define a hierarchy of classes, say with "Car" and "Truck" being sub-classes of "Vehicle", each having a concrete implementation, and have an expression returning either a "Car" or a "Truck", or maybe even a "Vehicle". This expression will be statically typed as returning a "Vehicle", yet the dynamic type of the returned value will not necessary be (exactly) that.
tmtvl•2mo ago
Could be a Raku construct:
my $day-of-week = 5 but "Friday";
o11c•2mo ago
Any statically-typed language has this. In pseudo-Java:
class Parent {};
class Child extends Parent {};
class Wrapper
{
Parent foo;
}
w = new Wrapper();
w.foo = new Child();
evaluate w.foo;
// static type: Parent
// dynamic type: Child
o11c•2mo ago
ahoka•2mo ago
suspended_state•2mo ago
For instance, in typescript you could ascribe an expression with the type Any, yet the actual runtime type will not be Any, it will be any concrete type.
In object oriented languages, you may define a hierarchy of classes, say with "Car" and "Truck" being sub-classes of "Vehicle", each having a concrete implementation, and have an expression returning either a "Car" or a "Truck", or maybe even a "Vehicle". This expression will be statically typed as returning a "Vehicle", yet the dynamic type of the returned value will not necessary be (exactly) that.
tmtvl•2mo ago
o11c•2mo ago