Add base piping for list.Replace

This commit is contained in:
Brendan Hansknecht 2022-02-24 17:58:56 -08:00
parent 279652a5af
commit ba2e8cd32b
14 changed files with 315 additions and 16 deletions

View file

@ -354,6 +354,8 @@ pub const LIST_RANGE: &str = "roc_builtins.list.range";
pub const LIST_REVERSE: &str = "roc_builtins.list.reverse";
pub const LIST_SORT_WITH: &str = "roc_builtins.list.sort_with";
pub const LIST_CONCAT: &str = "roc_builtins.list.concat";
pub const LIST_REPLACE: &str = "roc_builtins.list.replace";
pub const LIST_REPLACE_IN_PLACE: &str = "roc_builtins.list.replace_in_place";
pub const LIST_SET: &str = "roc_builtins.list.set";
pub const LIST_SET_IN_PLACE: &str = "roc_builtins.list.set_in_place";
pub const LIST_ANY: &str = "roc_builtins.list.any";

View file

@ -4,9 +4,9 @@ use roc_module::symbol::Symbol;
use roc_region::all::Region;
use roc_types::builtin_aliases::{
bool_type, dec_type, dict_type, f32_type, f64_type, float_type, i128_type, i16_type, i32_type,
i64_type, i8_type, int_type, list_type, nat_type, num_type, ordering_type, result_type,
set_type, str_type, str_utf8_byte_problem_type, u128_type, u16_type, u32_type, u64_type,
u8_type,
i64_type, i8_type, int_type, list_type, nat_type, num_type, ordering_type, pair_type,
result_type, set_type, str_type, str_utf8_byte_problem_type, u128_type, u16_type, u32_type,
u64_type, u8_type,
};
use roc_types::solved_types::SolvedType;
use roc_types::subs::VarId;
@ -1034,7 +1034,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
add_top_level_function_type!(
Symbol::LIST_GET,
vec![list_type(flex(TVAR1)), nat_type()],
Box::new(result_type(flex(TVAR1), index_out_of_bounds)),
Box::new(result_type(flex(TVAR1), index_out_of_bounds.clone())),
);
// first : List elem -> Result elem [ ListWasEmpty ]*
@ -1056,6 +1056,16 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
Box::new(result_type(flex(TVAR1), list_was_empty.clone())),
);
// replace : List elem, Nat, elem -> Result (Pair (List elem) elem) [ OutOfBounds ]*
add_top_level_function_type!(
Symbol::LIST_REPLACE,
vec![list_type(flex(TVAR1)), nat_type(), flex(TVAR1)],
Box::new(result_type(
pair_type(list_type(flex(TVAR1)), flex(TVAR1)),
index_out_of_bounds
)),
);
// set : List elem, Nat, elem -> List elem
add_top_level_function_type!(
Symbol::LIST_SET,