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

15 lines
332 B
Python

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