mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
setup
just some stuff we need in place for the parser to recognice map2 and to give it a (hardcoded) type
This commit is contained in:
parent
ff34950bf2
commit
2e73e47673
5 changed files with 23 additions and 0 deletions
|
@ -804,6 +804,19 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
|||
)
|
||||
});
|
||||
|
||||
// map2 : List a, List b, (a, b -> c) -> List c
|
||||
add_type(Symbol::LIST_MAP2, {
|
||||
let_tvars! {a, b, c, cvar};
|
||||
top_level_function(
|
||||
vec![
|
||||
list_type(flex(a)),
|
||||
list_type(flex(b)),
|
||||
closure(vec![flex(a), flex(b)], cvar, Box::new(flex(c))),
|
||||
],
|
||||
Box::new(list_type(flex(c))),
|
||||
)
|
||||
});
|
||||
|
||||
// append : List elem, elem -> List elem
|
||||
add_type(
|
||||
Symbol::LIST_APPEND,
|
||||
|
|
|
@ -80,6 +80,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
|
|||
LIST_PREPEND => list_prepend,
|
||||
LIST_JOIN => list_join,
|
||||
LIST_MAP => list_map,
|
||||
LIST_MAP2 => list_map2,
|
||||
LIST_MAP_WITH_INDEX => list_map_with_index,
|
||||
LIST_KEEP_IF => list_keep_if,
|
||||
LIST_KEEP_OKS => list_keep_oks,
|
||||
|
@ -215,6 +216,7 @@ pub fn builtin_defs(var_store: &mut VarStore) -> MutMap<Symbol, Def> {
|
|||
Symbol::LIST_PREPEND => list_prepend,
|
||||
Symbol::LIST_JOIN => list_join,
|
||||
Symbol::LIST_MAP => list_map,
|
||||
Symbol::LIST_MAP2 => list_map2,
|
||||
Symbol::LIST_MAP_WITH_INDEX => list_map_with_index,
|
||||
Symbol::LIST_KEEP_IF => list_keep_if,
|
||||
Symbol::LIST_KEEP_OKS => list_keep_oks,
|
||||
|
@ -2113,6 +2115,11 @@ fn list_map_with_index(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
lowlevel_2(symbol, LowLevel::ListMapWithIndex, var_store)
|
||||
}
|
||||
|
||||
/// List.map2 : List a, List b, (a, b -> c) -> List c
|
||||
fn list_map2(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
lowlevel_3(symbol, LowLevel::ListMap2, var_store)
|
||||
}
|
||||
|
||||
/// Dict.hashTestOnly : k, v -> Nat
|
||||
pub fn dict_hash_test_only(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
lowlevel_2(symbol, LowLevel::Hash, var_store)
|
||||
|
|
|
@ -27,6 +27,7 @@ pub enum LowLevel {
|
|||
ListPrepend,
|
||||
ListJoin,
|
||||
ListMap,
|
||||
ListMap2,
|
||||
ListMapWithIndex,
|
||||
ListKeepIf,
|
||||
ListWalk,
|
||||
|
|
|
@ -909,6 +909,7 @@ define_builtins! {
|
|||
21 LIST_KEEP_OKS: "keepOks"
|
||||
22 LIST_KEEP_ERRS: "keepErrs"
|
||||
23 LIST_MAP_WITH_INDEX: "mapWithIndex"
|
||||
24 LIST_MAP2: "map2"
|
||||
}
|
||||
5 RESULT: "Result" => {
|
||||
0 RESULT_RESULT: "Result" imported // the Result.Result type alias
|
||||
|
|
|
@ -651,6 +651,7 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
|
|||
StrJoinWith => arena.alloc_slice_copy(&[borrowed, borrowed]),
|
||||
ListJoin => arena.alloc_slice_copy(&[irrelevant]),
|
||||
ListMap | ListMapWithIndex => arena.alloc_slice_copy(&[owned, irrelevant]),
|
||||
ListMap2 => arena.alloc_slice_copy(&[owned, owned, irrelevant]),
|
||||
ListKeepIf | ListKeepOks | ListKeepErrs => arena.alloc_slice_copy(&[owned, borrowed]),
|
||||
ListContains => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
||||
ListWalk => arena.alloc_slice_copy(&[owned, irrelevant, owned]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue