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:
20
src/types.rs
20
src/types.rs
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user