Pre-RFC: Anonymous variant types

If it really forbids naming such a type, then the compiler is required to perform post-instantiation type checking once the type variables are bound to concrete types. I.e., we would be back in C++ template land, where the body and the signature of a function might or might not compile based on the values it’s called with. I would really-really not like to go there.

Or, we could just forbid a generic type variable in an anonymous variant type altogether, although that probably severely limits their usefulness.

Another “solution” would be to actually make them union types instead of sum types (so that duplicates are filtered out), although union types can be very surprising to use and reason about. E.g. a couple of young functional languages with union types define Option<T> as T union null, and then Option<Option<T>> == Option<T> and other ambiguous pain points arise. Needless to say, I’d rather not do that either.

1 Like