Skip to content

Commit

Permalink
Add Sort ability
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jwoudenberg committed May 6, 2024
1 parent f4291f4 commit 87b99fd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions crates/compiler/builtins/roc/List.roc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ module [
walkBackwardsUntil,
countIf,
chunksOf,
Sort,
compare,
]

import Bool exposing [Bool, Eq]
Expand Down Expand Up @@ -1324,3 +1326,6 @@ iterBackwardsHelp = \list, state, f, prevIndex ->
Break b -> Break b
else
Continue state

Sort implements
compare : a, a -> [LessThan, Equal, GreaterThan] where a implements Sort
1 change: 1 addition & 0 deletions crates/compiler/builtins/roc/main.roc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package [
List,
Dict,
Set,
Sort
Decode,
Encode,
Hash,
Expand Down
7 changes: 6 additions & 1 deletion crates/compiler/module/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub const DERIVABLE_ABILITIES: &[(Symbol, &[Symbol])] = &[
(Symbol::DECODE_DECODING, &[Symbol::DECODE_DECODER]),
(Symbol::HASH_HASH_ABILITY, &[Symbol::HASH_HASH]),
(Symbol::BOOL_EQ, &[Symbol::BOOL_IS_EQ]),
(Symbol::LIST_SORT, &[Symbol::LIST_COMPARE]),
(
Symbol::INSPECT_INSPECT_ABILITY,
&[Symbol::INSPECT_TO_INSPECTOR],
Expand Down Expand Up @@ -1739,6 +1740,10 @@ define_builtins! {
5 JSON_ARRAY_CLOSING_STATE: "ArrayClosingState"
6 JSON_OBJECT_STATE: "ObjectState"
}
16 SORT: "Sort" => {
0 LIST_SORT: "Sort"
1 LIST_COMPARE: "compare"
}

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)
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)
}

0 comments on commit 87b99fd

Please sign in to comment.