Skip to content

Commit 592b2bb

Browse files
committed
---
yaml --- r: 27687 b: refs/heads/try c: 8703d08 h: refs/heads/master i: 27685: d65784b 27683: d960edc 27679: 3e22d8d v: v3
1 parent 524f7e1 commit 592b2bb

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

[refs]

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

0 commit comments

Comments
 (0)