Skip to content

Commit 7dd65f2

Browse files
committed
---
yaml --- r: 21001 b: refs/heads/snap-stage3 c: 8703d08 h: refs/heads/master i: 20999: 39fb9cc v: v3
1 parent 61c9a66 commit 7dd65f2

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: e82d2ef7639252ba365427ea1ad0e285986b5bf8
4+
refs/heads/snap-stage3: 8703d088ead97cff975187bcd5b57851ad410cbe
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
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)