-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional test for unboxing and bump version
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//@execute 0=0; 1=12; 2=44; 3=288; 5=0 | ||
|
||
type T<E> #unboxed { | ||
case Leaf(x: E); | ||
case One(a: T<E>.Leaf, b: T<E>.Leaf); | ||
case Two(a: T<E>.One, b: T<E>.One); | ||
} | ||
|
||
def count1 = int.!<int>; | ||
def count2 = int.+; | ||
|
||
def main(a: int) -> int { | ||
var x = make<int>(a, 3); | ||
var y = make<(int, int)>(a, (4, 5)); | ||
|
||
return count(x, count1) + count(y, count2); | ||
} | ||
|
||
def count<E>(t: T<E>, num: E -> int) -> int { | ||
match (t) { | ||
Leaf(x) => return num(x); | ||
One(a, b) => return 10 + count(a, num) + count(b, num); | ||
Two(a, b) => return 100 + count(a, num) + count(b, num); | ||
} | ||
} | ||
|
||
def make<E>(a: int, val: E) -> T<E> { | ||
var d: T<E>; | ||
var leaf = T<E>.Leaf(val); | ||
var one = T<E>.One(leaf, leaf); | ||
var two = T<E>.Two(one, one); | ||
|
||
if (a == 1) return leaf; | ||
if (a == 2) return one; | ||
if (a == 3) return two; | ||
|
||
return d; | ||
} |