Skip to content

Commit e13771a

Browse files
committed
---
yaml --- r: 21002 b: refs/heads/snap-stage3 c: 812db1e h: refs/heads/master v: v3
1 parent 7dd65f2 commit e13771a

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 8703d088ead97cff975187bcd5b57851ad410cbe
4+
refs/heads/snap-stage3: 812db1ec0d97217414b4e49962e8da75761b9279
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Example from lkuper's intern talk, August 2012 -- now with static
2+
// methods!
3+
4+
trait Equal {
5+
static fn isEq(a: self, b: self) -> bool;
6+
}
7+
8+
enum Color { cyan, magenta, yellow, black }
9+
10+
impl Color : Equal {
11+
static fn isEq(a: Color, b: Color) -> bool {
12+
match (a, b) {
13+
(cyan, cyan) => { true }
14+
(magenta, magenta) => { true }
15+
(yellow, yellow) => { true }
16+
(black, black) => { true }
17+
_ => { false }
18+
}
19+
}
20+
}
21+
22+
enum ColorTree {
23+
leaf(Color),
24+
branch(@ColorTree, @ColorTree)
25+
}
26+
27+
impl ColorTree : Equal {
28+
static fn isEq(a: ColorTree, b: ColorTree) -> bool {
29+
match (a, b) {
30+
(leaf(x), leaf(y)) => { isEq(x, y) }
31+
(branch(l1, r1), branch(l2, r2)) => {
32+
isEq(*l1, *l2) && isEq(*r1, *r2)
33+
}
34+
_ => { false }
35+
}
36+
}
37+
}
38+
39+
fn main() {
40+
assert isEq(cyan, cyan);
41+
assert isEq(magenta, magenta);
42+
assert !isEq(cyan, yellow);
43+
assert !isEq(magenta, cyan);
44+
45+
assert isEq(leaf(cyan), leaf(cyan));
46+
assert !isEq(leaf(cyan), leaf(yellow));
47+
48+
assert isEq(branch(@leaf(magenta), @leaf(cyan)),
49+
branch(@leaf(magenta), @leaf(cyan)));
50+
51+
assert !isEq(branch(@leaf(magenta), @leaf(cyan)),
52+
branch(@leaf(magenta), @leaf(magenta)));
53+
54+
log(error, "Assertions all succeeded!");
55+
}

0 commit comments

Comments
 (0)