feat: add List.sort and List.sortBy functions (issue 9)

Add sorting support to the List module across all backends:
- List.sort for natural ordering (Int, Float, String, Bool, Char)
- List.sortBy for custom comparator-based sorting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-20 10:02:21 -05:00
parent 1fc472a54c
commit 091ff1e422
4 changed files with 225 additions and 1 deletions

View File

@@ -1551,6 +1551,26 @@ impl TypeEnv {
Type::Unit,
),
),
(
"sort".to_string(),
Type::function(
vec![Type::List(Box::new(Type::var()))],
Type::List(Box::new(Type::var())),
),
),
(
"sortBy".to_string(),
{
let elem = Type::var();
Type::function(
vec![
Type::List(Box::new(elem.clone())),
Type::function(vec![elem.clone(), elem], Type::Int),
],
Type::List(Box::new(Type::var())),
)
},
),
]);
env.bind("List", TypeScheme::mono(list_module_type));