Skip to content

Commit 19709ab

Browse files
committed
Add Sort ability
This adds a Sort ability, currently lacking any implementations of the ability. It's an open question whether this should be defined in a new top-level Roc builtin. I can also see an argument for putting it in the List module, and maybe there's other options. I plan to get some input on this point before making a decision.
1 parent 3960a56 commit 19709ab

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

crates/compiler/builtins/roc/List.roc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ module [
6969
walkBackwardsUntil,
7070
countIf,
7171
chunksOf,
72+
Sort,
73+
compare,
7274
]
7375

7476
import Bool exposing [Bool, Eq]
@@ -1324,3 +1326,6 @@ iterBackwardsHelp = \list, state, f, prevIndex ->
13241326
Break b -> Break b
13251327
else
13261328
Continue state
1329+
1330+
Sort implements
1331+
compare : a, a -> [LessThan, Equal, GreaterThan] where a implements Sort

crates/compiler/builtins/roc/main.roc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package [
66
List,
77
Dict,
88
Set,
9+
Sort
910
Decode,
1011
Encode,
1112
Hash,

crates/compiler/module/src/symbol.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub const DERIVABLE_ABILITIES: &[(Symbol, &[Symbol])] = &[
5353
(Symbol::DECODE_DECODING, &[Symbol::DECODE_DECODER]),
5454
(Symbol::HASH_HASH_ABILITY, &[Symbol::HASH_HASH]),
5555
(Symbol::BOOL_EQ, &[Symbol::BOOL_IS_EQ]),
56+
(Symbol::LIST_SORT, &[Symbol::LIST_COMPARE]),
5657
(
5758
Symbol::INSPECT_INSPECT_ABILITY,
5859
&[Symbol::INSPECT_TO_INSPECTOR],
@@ -1735,6 +1736,10 @@ define_builtins! {
17351736
5 JSON_ARRAY_CLOSING_STATE: "ArrayClosingState"
17361737
6 JSON_OBJECT_STATE: "ObjectState"
17371738
}
1739+
16 SORT: "Sort" => {
1740+
0 LIST_SORT: "Sort"
1741+
1 LIST_COMPARE: "compare"
1742+
}
17381743

1739-
num_modules: 16 // Keep this count up to date by hand! (TODO: see the mut_map! macro for how we could determine this count correctly in the macro)
1744+
num_modules: 17 // Keep this count up to date by hand! (TODO: see the mut_map! macro for how we could determine this count correctly in the macro)
17401745
}

0 commit comments

Comments
 (0)