-
Notifications
You must be signed in to change notification settings - Fork 168
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
1 parent
3b07c76
commit 3a507d9
Showing
2 changed files
with
23 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Issue: https://github.com/koka-lang/koka/issues/186 | ||
alias elem = int | ||
|
||
fun sequences(xs : list<elem>) | ||
match xs | ||
Cons(a, Cons(b, xs)) -> | ||
if(a > b) then descending(b, [a], xs) | ||
else ascending(b, (fn(x) { Cons(a, x) }), xs) | ||
_ -> [xs] // This uses a name both in scope outside the match and inside the other match branch. Uniquify should not substitute this. | ||
|
||
fun descending(a : elem, as_, bs) | ||
match bs | ||
Cons(b, bs) | a > b -> descending(b, Cons(a, as_), bs) | ||
_ -> Cons(Cons(a, as_), sequences(bs)) | ||
|
||
fun ascending(a : elem, as_, bs) | ||
match bs | ||
Cons(b, bs) | !(a > b) -> ascending(b, fn(ys) { as_(Cons(a, ys)) }, bs) | ||
_ -> Cons(as_([a]), sequences(bs)) | ||
|
||
fun main() | ||
sequences([0, 1, 2, 3]) |
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 @@ | ||
[[0,1,2,3],[]] |