mirror of
https://github.com/erg-lang/erg.git
synced 2025-07-16 09:35:19 +00:00
31 lines
631 B
Python
31 lines
631 B
Python
name n: Structural { .name = Str } = n.name
|
|
|
|
C = Class { .name = Str }
|
|
C.
|
|
new name = C { .name = name }
|
|
D = Class { .name = Str; .id = Nat }
|
|
D.
|
|
new name, id = D { .name = name; .id = id }
|
|
|
|
c = C.new "foo"
|
|
d = D.new "bar", 1
|
|
|
|
assert name(c) == "foo"
|
|
assert name(d) == "bar"
|
|
|
|
inner|T| x: Structural { .inner = T } = x.inner
|
|
|
|
E = Class { .inner = Int }
|
|
E.
|
|
new inner = E { .inner = inner }
|
|
__add__ self, other: E = E { .inner = self.inner + other.inner }
|
|
|
|
e = E.new 1
|
|
|
|
assert inner(e) == 1
|
|
|
|
add|T, U, V| x: Structural({ .__add__ = (self: T, other: U) -> V }), other: U =
|
|
x.__add__(other)
|
|
|
|
_ = add 1, 2
|
|
_ = add e, e
|