nac3-spec/toy-impl/examples/a.py

17 lines
439 B
Python

I = TypeVar('I', int32, float, Vec)
class Vec:
v: list[int32]
def __init__(self, v: list[int32]):
self.v = v
def __add__(self, other: I) -> Vec:
if type(other) == int32:
return Vec([v + other for v in self.v])
elif type(other) == float:
return Vec([v + int32(other) for v in self.v])
else:
return Vec([self.v[i] + other.v[i] for i in range(len(self.v))])