Open dbenn opened 3 years ago
We might simply allow a function to be able to take or return one of N types and to allow that to be checked at run time, which makes variant types vs ANY the best approach here.
Note that:
(real or string or list)
or
(real | string | list)
makes sense as a variant type. Later we may want to allow typed N-tuples (or records), which could be like this:
(real string list)
Further to an earlier point, there should be no need for a variable to have a variant type, just function parameters and return values.
The following method in Type
will be useful for type checking variant types: oneOf
.
Another way of approaching this would be to implement polymorphism in VeLa such that a parameter or return type would be associated with a type variable with instances of functions instantiated with concrete types. This may add unnecessary complexity to VeLa, but is worth at least considering for completeness. Given that we are not planning to allow the creation of arbitrarily complex types in VeLa, full general polymorphism/generics may be overkill. Will muse over this.
Be clear about the motivation here, in particular, why function overloading (that we have now) is not sufficient, e.g. for return types, for I/O functions?