mirror of
https://github.com/erg-lang/erg.git
synced 2025-12-23 05:36:48 +00:00
20 lines
385 B
Python
20 lines
385 B
Python
add|T: Type, U: Type, V: Type| x: Structural({ .__add__ = (self: T, other: U) -> V }), other: U =
|
|
x.__add__(other)
|
|
|
|
a = add 1, 2
|
|
b = add a, 2
|
|
c = add b, 2
|
|
assert c == 7
|
|
|
|
_add x, y = add x, y
|
|
|
|
x = _add 1, 2
|
|
y = _add x, 2
|
|
z = _add y, 2
|
|
assert z == 7
|
|
|
|
w = _add -1, 2
|
|
assert w == 1
|
|
|
|
gt|T, U| x: Structural({.__gt__ = (self: T, other: U) -> Bool}), y: U = x.__gt__ y
|
|
assert gt(2, True)
|