mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
List prepend implementation with tests, and a few small code clarity changes to list_push implementation
This commit is contained in:
parent
fc52bdc59a
commit
68b13d29fd
7 changed files with 214 additions and 10 deletions
|
@ -510,7 +510,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
|||
),
|
||||
);
|
||||
|
||||
// push : List elem -> elem -> List elem
|
||||
// push : List elem, elem -> List elem
|
||||
add_type(
|
||||
Symbol::LIST_PUSH,
|
||||
SolvedType::Func(
|
||||
|
@ -519,6 +519,15 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
|||
),
|
||||
);
|
||||
|
||||
// prepend : List elem, elem -> List elem
|
||||
add_type(
|
||||
Symbol::LIST_PREPEND,
|
||||
SolvedType::Func(
|
||||
vec![list_type(flex(TVAR1)), flex(TVAR1)],
|
||||
Box::new(list_type(flex(TVAR1))),
|
||||
),
|
||||
);
|
||||
|
||||
// single : a -> List a
|
||||
add_type(
|
||||
Symbol::LIST_SINGLE,
|
||||
|
|
|
@ -699,6 +699,36 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
|||
)
|
||||
});
|
||||
|
||||
// prepend : Attr * (List a)
|
||||
// , a
|
||||
// -> Attr * (List a)
|
||||
//
|
||||
// NOTE: we demand the new item to have the same uniqueness as the other list items.
|
||||
// It could be allowed to add unique items to shared lists, but that requires special code gen
|
||||
add_type(Symbol::LIST_PREPEND, {
|
||||
let_tvars! { a, star1, star2 };
|
||||
|
||||
unique_function(
|
||||
vec![
|
||||
SolvedType::Apply(
|
||||
Symbol::ATTR_ATTR,
|
||||
vec![
|
||||
flex(star1),
|
||||
SolvedType::Apply(Symbol::LIST_LIST, vec![flex(a)]),
|
||||
],
|
||||
),
|
||||
flex(a),
|
||||
],
|
||||
SolvedType::Apply(
|
||||
Symbol::ATTR_ATTR,
|
||||
vec![
|
||||
boolean(star2),
|
||||
SolvedType::Apply(Symbol::LIST_LIST, vec![flex(a)]),
|
||||
],
|
||||
),
|
||||
)
|
||||
});
|
||||
|
||||
// List.map does not need to check the container rule on the input list.
|
||||
// There is no way in which this signature can cause unique values to be duplicated
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue