mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
attempt to make examples more generic
This commit is contained in:
parent
2ca6f0107a
commit
1ac66a8fee
3 changed files with 15 additions and 10 deletions
|
@ -6556,11 +6556,15 @@ fn from_can_pattern_help<'a>(
|
|||
let mut arguments = arguments.clone();
|
||||
|
||||
arguments.sort_by(|arg1, arg2| {
|
||||
let layout1 = layout_cache.from_var(env.arena, arg1.0, env.subs).unwrap();
|
||||
let layout2 = layout_cache.from_var(env.arena, arg2.0, env.subs).unwrap();
|
||||
let size1 = layout_cache
|
||||
.from_var(env.arena, arg1.0, env.subs)
|
||||
.map(|x| x.alignment_bytes(env.ptr_bytes))
|
||||
.unwrap_or(0);
|
||||
|
||||
let size1 = layout1.alignment_bytes(env.ptr_bytes);
|
||||
let size2 = layout2.alignment_bytes(env.ptr_bytes);
|
||||
let size2 = layout_cache
|
||||
.from_var(env.arena, arg2.0, env.subs)
|
||||
.map(|x| x.alignment_bytes(env.ptr_bytes))
|
||||
.unwrap_or(0);
|
||||
|
||||
size2.cmp(&size1)
|
||||
});
|
||||
|
|
|
@ -60,7 +60,7 @@ main =
|
|||
Nil ->
|
||||
Task.putLine "fail"
|
||||
|
||||
insert : Map, I64, Bool -> Map
|
||||
insert : Tree (Num k) v, (Num k), v -> Tree (Num k) v
|
||||
insert = \t, k, v -> if isRed t then setBlack (ins t k v) else ins t k v
|
||||
|
||||
|
||||
|
@ -78,7 +78,7 @@ isRed = \tree ->
|
|||
|
||||
lt = \x, y -> x < y
|
||||
|
||||
ins : Map, I64, Bool -> Map
|
||||
ins : Tree (Num k) v, (Num k), v -> Tree (Num k) v
|
||||
ins = \tree, kx, vx ->
|
||||
when tree is
|
||||
Leaf ->
|
||||
|
@ -100,7 +100,7 @@ ins = \tree, kx, vx ->
|
|||
else
|
||||
Node Black a kx vx b
|
||||
|
||||
balance1 : Map, Map -> Map
|
||||
balance1 : Tree a b, Tree a b -> Tree a b
|
||||
balance1 = \tree1, tree2 ->
|
||||
when tree1 is
|
||||
Leaf -> Leaf
|
||||
|
@ -111,7 +111,7 @@ balance1 = \tree1, tree2 ->
|
|||
Node _ l ky vy r -> Node Black (Node Red l ky vy r) kv vv t
|
||||
Leaf -> Leaf
|
||||
|
||||
balance2 : Map, Map -> Map
|
||||
balance2 : Tree a b, Tree a b -> Tree a b
|
||||
balance2 = \tree1, tree2 ->
|
||||
when tree1 is
|
||||
Leaf -> Leaf
|
||||
|
|
|
@ -87,7 +87,7 @@ isRed = \tree ->
|
|||
|
||||
lt = \x, y -> x < y
|
||||
|
||||
ins : Map, I64, Bool -> Map
|
||||
ins : Tree I64 Bool, I64, Bool -> Tree I64 Bool
|
||||
ins = \tree, kx, vx ->
|
||||
when tree is
|
||||
Leaf ->
|
||||
|
@ -188,11 +188,12 @@ delMin = \t ->
|
|||
|
||||
|
||||
|
||||
delete : Map, I64 -> Map
|
||||
delete : Tree I64 Bool, I64 -> Tree I64 Bool
|
||||
delete = \t, k ->
|
||||
when del t k is
|
||||
Del tx _ -> setBlack tx
|
||||
|
||||
del : Tree I64 Bool, I64 -> Del I64 Bool
|
||||
del = \t, k ->
|
||||
when t is
|
||||
Leaf -> Del Leaf False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue