AAVSO / VStar

VStar is a visualisation and analysis tool for variable star data brought to you by AAVSO
https://www.aavso.org/vstar
GNU Affero General Public License v3.0
9 stars 3 forks source link

Allow variant types such as (real | string | list) #199

Open dbenn opened 3 years ago

dbenn commented 3 years ago

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?

dbenn commented 1 year 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)
dbenn commented 1 year ago

Further to an earlier point, there should be no need for a variable to have a variant type, just function parameters and return values.

dbenn commented 4 months ago

The following method in Type will be useful for type checking variant types: oneOf.

dbenn commented 2 weeks ago

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.