claro-lang
claro-lang copied to clipboard
Support One-Of Types for Undecidable Types That Programmer Can't Even Decide at Compile-Time
Basically in the situation:
var t = (1, "hello");
var x = t[randomChoice(0, 1)];
there's no way for compiler OR programmer to decide the type of the variable x
at compile-time.
So I think we need some way to represent that situation in a type-safe manner. Let's try a new concept of OneOf Types and see what happens. (Btw, this would tie in well with a match stmt).
var t = (1, "hello");
var x: oneof<int | string> = t[randomChoice(0, 1)];
match type(x) {
int -> ...
string -> ...
}