3 ms·
What is the return type of an overloaded function? I don't see that in any of the examples. I think it would make sense to have each function return either the
by paddy_m 1y ago
What is the return type of an overloaded function? I don't see that in any of the examples.
I think it would make sense to have each function return either the exact same type, or a generic.
@ovld(int) #all of these overloads should return an int
len(a:list) -> int
len(a:str) -> int
#the effective type of len is
len(a:Union[int, str]) -> int
and then a generic example
T = TypeVar('T')
@ovld(T)
add(a:np.int8, b:np.int8) -> np.int8
@ovld(T)
add(a:np.int16, b:np.int16) -> np.int16
In the second example, I don't know how you would connect the input params to the generic T. If you put concrete types in, I see how ovld works.
Am I missing something?