diff --git a/compiler/load/tests/fixtures/build/app_with_deps/Quicksort.roc b/compiler/load/tests/fixtures/build/app_with_deps/Quicksort.roc index 1d363a1b5b..9cbf0c7e38 100644 --- a/compiler/load/tests/fixtures/build/app_with_deps/Quicksort.roc +++ b/compiler/load/tests/fixtures/build/app_with_deps/Quicksort.roc @@ -1,5 +1,5 @@ app Quicksort - provides [ swap, partition, quicksort ] + provides [ swap, partition, partitionHelp, quicksort ] imports [] quicksort : List (Num a), Int, Int -> List (Num a) @@ -27,23 +27,25 @@ partition : Int, Int, List (Num a) -> [ Pair Int (List (Num a)) ] partition = \low, high, initialList -> when List.get initialList high is Ok pivot -> - go = \i, j, list -> - if j < high then - when List.get list j is - Ok value -> - if value <= pivot then - go (i + 1) (j + 1) (swap (i + 1) j list) - else - go i (j + 1) list - - Err _ -> - Pair i list - else - Pair i list - - when go (low - 1) low initialList is + when partitionHelp (low - 1) low initialList high pivot is Pair newI newList -> Pair (newI + 1) (swap (newI + 1) high newList) Err _ -> Pair (low - 1) initialList + + +partitionHelp : Int, Int, List (Num a), Int, (Num a) -> [ Pair Int (List (Num a)) ] +partitionHelp = \i, j, list, high, pivot -> + if j < high then + when List.get list j is + Ok value -> + if value <= pivot then + partitionHelp (i + 1) (j + 1) (swap (i + 1) j list) high pivot + else + partitionHelp i (j + 1) list high pivot + + Err _ -> + Pair i list + else + Pair i list diff --git a/compiler/load/tests/fixtures/build/interface_with_deps/Quicksort.roc b/compiler/load/tests/fixtures/build/interface_with_deps/Quicksort.roc index 9f02ef5b3d..d4e9b79490 100644 --- a/compiler/load/tests/fixtures/build/interface_with_deps/Quicksort.roc +++ b/compiler/load/tests/fixtures/build/interface_with_deps/Quicksort.roc @@ -27,23 +27,25 @@ partition : Int, Int, List (Num a) -> [ Pair Int (List (Num a)) ] partition = \low, high, initialList -> when List.get initialList high is Ok pivot -> - go = \i, j, list -> - if j < high then - when List.get list j is - Ok value -> - if value <= pivot then - go (i + 1) (j + 1) (swap (i + 1) j list) - else - go i (j + 1) list - - Err _ -> - Pair i list - else - Pair i list - - when go (low - 1) low initialList is + when partitionHelp (low - 1) low initialList high pivot is Pair newI newList -> Pair (newI + 1) (swap (newI + 1) high newList) Err _ -> Pair (low - 1) initialList + + +partitionHelp : Int, Int, List (Num a), Int, (Num a) -> [ Pair Int (List (Num a)) ] +partitionHelp = \i, j, list, high, pivot -> + if j < high then + when List.get list j is + Ok value -> + if value <= pivot then + partitionHelp (i + 1) (j + 1) (swap (i + 1) j list) high pivot + else + partitionHelp i (j + 1) list high pivot + + Err _ -> + Pair i list + else + Pair i list diff --git a/compiler/load/tests/test_load.rs b/compiler/load/tests/test_load.rs index e98f05dfdc..69bcb0f483 100644 --- a/compiler/load/tests/test_load.rs +++ b/compiler/load/tests/test_load.rs @@ -214,6 +214,7 @@ mod test_load { hashmap! { "swap" => "Int, Int, List a -> List a", "partition" => "Int, Int, List (Num a) -> [ Pair Int (List (Num a)) ]", + "partitionHelp" => "Int, Int, List (Num a), Int, Num a -> [ Pair Int (List (Num a)) ]", "quicksort" => "List (Num a), Int, Int -> List (Num a)", }, ); @@ -229,6 +230,7 @@ mod test_load { hashmap! { "swap" => "Int, Int, List a -> List a", "partition" => "Int, Int, List (Num a) -> [ Pair Int (List (Num a)) ]", + "partitionHelp" => "Int, Int, List (Num a), Int, Num a -> [ Pair Int (List (Num a)) ]", "quicksort" => "List (Num a), Int, Int -> List (Num a)", }, ); diff --git a/compiler/load/tests/test_uniq_load.rs b/compiler/load/tests/test_uniq_load.rs index 4ee214f80f..052cfdc66f 100644 --- a/compiler/load/tests/test_uniq_load.rs +++ b/compiler/load/tests/test_uniq_load.rs @@ -233,6 +233,8 @@ mod test_uniq_load { hashmap! { "swap" => "Attr * (Attr * Int, Attr * Int, Attr * (List (Attr Shared a)) -> Attr * (List (Attr Shared a)))", "partition" => "Attr * (Attr Shared Int, Attr Shared Int, Attr b (List (Attr Shared (Num (Attr Shared a)))) -> Attr * [ Pair (Attr * Int) (Attr b (List (Attr Shared (Num (Attr Shared a))))) ])", + + "partitionHelp" => "Attr Shared (Attr b Int, Attr Shared Int, Attr c (List (Attr Shared (Num (Attr Shared a)))), Attr Shared Int, Attr Shared (Num (Attr Shared a)) -> Attr * [ Pair (Attr b Int) (Attr c (List (Attr Shared (Num (Attr Shared a))))) ])", "quicksort" => "Attr Shared (Attr b (List (Attr Shared (Num (Attr Shared a)))), Attr Shared Int, Attr Shared Int -> Attr b (List (Attr Shared (Num (Attr Shared a)))))", }, );