claro-lang icon indicating copy to clipboard operation
claro-lang copied to clipboard

Support One-Of Types for Undecidable Types That Programmer Can't Even Decide at Compile-Time

Open JasonSteving99 opened this issue 3 years ago • 0 comments

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 -> ...
}

JasonSteving99 avatar Sep 13 '21 04:09 JasonSteving99