|
|
|
|
|
by hrjet
4672 days ago
|
|
But isn't that how type inference works in most statically typed languages? For example, in Scala:
val x = if (some_condition) Employer else Employee If Employer and Employee both derive from Person, then x will be of type Person. The run time uses dynamic dispatch to figure out how members are accessed from x. If you want to constrain x, you need to specify the type explicitly. |
|
In your example, the type of x is not (Employer \/ Employee), it is their shared superclass - Person. The analogous example would be if
succeeded even though Employer and Employee did not share a superclass. Very few languages use union types - Typed Racket comes to mind, and Algol apparently did too.