Type union over set of values

How can I denote the set of types Val{x} where x is a Symbol?

Something like Val{S} where {S isa Symbol}, but this is not a legal expression. Is there a way to express such a Union type in Julia?

This is a particular example of a parametric type union where the parameter is restricted to a set of values, instead of a set of types.

You can’t express this constraint using only the type system. But you can create a wrapper type that has nothing but a type parameter and validates that it is a Val with a Symbol as type parameter.

1 Like