-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 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,7 @@ | ||
cons 9 (cons 7 (cons 5 (cons 3 (cons 1 nil)))) | ||
-12096 | ||
-1448007509520 | ||
5510602057585725 | ||
-85667472308246220 | ||
527851146861989286336 | ||
-441596546382859135501706333021475 |
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,49 @@ | ||
-- match | ||
|
||
constr cons 2; | ||
constr nil 0; | ||
|
||
def lgen := \n if n = 0 then nil else cons n (lgen (n - 1)); | ||
|
||
def sum2 := \x { | ||
match x with { | ||
cons x y@(cons z _) -> cons (x + z) (sum2 y); | ||
_ -> x | ||
} | ||
}; | ||
|
||
constr leaf 0; | ||
constr node 2; | ||
|
||
def gen := \n if n <= 0 then leaf else node (gen (n - 2)) (gen (n - 1)); | ||
|
||
def g; | ||
|
||
def f := \t match t with { | ||
leaf -> 1; | ||
node l r -> | ||
match g l, g r with { | ||
leaf, leaf -> 0 - 6; | ||
node l r, leaf -> (f l + f r) * 2; | ||
node l1 r1, node l2 r2 -> (f l1 + f r1) * (f l2 + f r2); | ||
_, node l r -> (f l + f r) * (0 - 3) | ||
} | ||
}; | ||
|
||
def g := \t { | ||
match t with { | ||
leaf -> t; | ||
node (node _ _) r -> r; | ||
node l r -> node r l; | ||
} | ||
}; | ||
|
||
def writeLn := \x write x >> write "\n"; | ||
|
||
writeLn (sum2 (lgen 5)) >> | ||
writeLn (f (gen 10)) >> | ||
writeLn (f (gen 15)) >> | ||
writeLn (f (gen 16)) >> | ||
writeLn (f (gen 17)) >> | ||
writeLn (f (gen 18)) >> | ||
writeLn (f (gen 20)) |