You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since I already implemented julia-style abstract types, I may as well implement union types. The easy way would be to just create a variant of TypeMatch that matches against multiple types and have the matched argument inferred as Value, which will result in the following semantics:
multifunction!{fnF(x: Union![i32, i64]) -> Value{
x + 1// x is of type Value}}fnmain(){println!("{}", F(1i32))// 2println!("{}", F(1i64))// 2}
But I wonder if it wouldn't be better if two methods were created, one where x is a i32 and another where x is a i64... That might be too tricky to handle even from the user's perspective, actually; in the above case, you would need to choose a return type that will work for both. One could convert x to i64 in this case because it's sort of a supertype, but if one had say a Union![f32, i64] this wouldn't work. One could convert x to Value but then that's just the first implementation, but more verbose. (Well, it's also opt-in...)
HMMMM...
The text was updated successfully, but these errors were encountered:
Since I already implemented julia-style abstract types, I may as well implement union types. The easy way would be to just create a variant of
TypeMatch
that matches against multiple types and have the matched argument inferred asValue
, which will result in the following semantics:But I wonder if it wouldn't be better if two methods were created, one where
x
is ai32
and another wherex
is ai64
... That might be too tricky to handle even from the user's perspective, actually; in the above case, you would need to choose a return type that will work for both. One could convert x toi64
in this case because it's sort of a supertype, but if one had say aUnion![f32, i64]
this wouldn't work. One could convertx
toValue
but then that's just the first implementation, but more verbose. (Well, it's also opt-in...)HMMMM...
The text was updated successfully, but these errors were encountered: