mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Merge branch 'trunk' into more-tea
This commit is contained in:
commit
3d9b82e35e
18 changed files with 188 additions and 184 deletions
|
@ -1,7 +1,7 @@
|
||||||
interface Defaults
|
interface Defaults
|
||||||
exposes []
|
exposes []
|
||||||
imports [
|
imports [
|
||||||
Map.{ Map },
|
Dict.{ Dict },
|
||||||
Set.{ Set },
|
Set.{ Set },
|
||||||
Num.{ Num, Int, Float }
|
Num.{ Num, Int, Float }
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
interface Map2
|
interface Dict2
|
||||||
exposes [ isEmpty, map ]
|
exposes [ isEmpty, map ]
|
||||||
imports []
|
imports []
|
||||||
|
|
||||||
isEmpty : Map * * -> Bool
|
isEmpty : Dict * * -> Bool
|
||||||
|
|
||||||
## Convert each key and value in the #Map to something new, by calling a conversion
|
## Convert each key and value in the #Dict to something new, by calling a conversion
|
||||||
## function on each of them. Then return a new #Map of the converted keys and values.
|
## function on each of them. Then return a new #Map of the converted keys and values.
|
||||||
##
|
##
|
||||||
## >>> Map.map {{ 3.14 => "pi", 1.0 => "one" }} \{ key, value } -> { key:
|
## >>> Dict.map {{ 3.14 => "pi", 1.0 => "one" }} \{ key, value } -> { key:
|
||||||
##
|
##
|
||||||
## >>> Map.map {[ "", "a", "bc" ]} Str.isEmpty
|
## >>> Dict.map {[ "", "a", "bc" ]} Str.isEmpty
|
||||||
##
|
##
|
||||||
## `map` functions like this are common in Roc, and they all work similarly.
|
## `map` functions like this are common in Roc, and they all work similarly.
|
||||||
## See for example #Result.map, #List.map, and #Set.map.
|
## See for example #Result.map, #List.map, and #Set.map.
|
|
@ -3,7 +3,7 @@ use roc_module::ident::TagName;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::Region;
|
use roc_region::all::Region;
|
||||||
use roc_types::builtin_aliases::{
|
use roc_types::builtin_aliases::{
|
||||||
bool_type, float_type, int_type, list_type, map_type, num_type, ordering_type, result_type,
|
bool_type, dict_type, float_type, int_type, list_type, num_type, ordering_type, result_type,
|
||||||
set_type, str_type,
|
set_type, str_type,
|
||||||
};
|
};
|
||||||
use roc_types::solved_types::SolvedType;
|
use roc_types::solved_types::SolvedType;
|
||||||
|
@ -30,7 +30,7 @@ pub fn standard_stdlib() -> StdLib {
|
||||||
applies: vec![
|
applies: vec![
|
||||||
Symbol::LIST_LIST,
|
Symbol::LIST_LIST,
|
||||||
Symbol::SET_SET,
|
Symbol::SET_SET,
|
||||||
Symbol::MAP_MAP,
|
Symbol::DICT_DICT,
|
||||||
Symbol::STR_STR,
|
Symbol::STR_STR,
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -614,39 +614,43 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||||
top_level_function(vec![list_type(flex(TVAR1))], Box::new(bool_type())),
|
top_level_function(vec![list_type(flex(TVAR1))], Box::new(bool_type())),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Map module
|
// Dict module
|
||||||
|
|
||||||
// empty : Map k v
|
// empty : Dict k v
|
||||||
add_type(Symbol::MAP_EMPTY, map_type(flex(TVAR1), flex(TVAR2)));
|
add_type(Symbol::DICT_EMPTY, dict_type(flex(TVAR1), flex(TVAR2)));
|
||||||
|
|
||||||
// singleton : k, v -> Map k v
|
// singleton : k, v -> Dict k v
|
||||||
add_type(
|
add_type(
|
||||||
Symbol::MAP_SINGLETON,
|
Symbol::DICT_SINGLETON,
|
||||||
top_level_function(
|
top_level_function(
|
||||||
vec![flex(TVAR1), flex(TVAR2)],
|
vec![flex(TVAR1), flex(TVAR2)],
|
||||||
Box::new(map_type(flex(TVAR1), flex(TVAR2))),
|
Box::new(dict_type(flex(TVAR1), flex(TVAR2))),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// get : Map k v, k -> Result v [ KeyNotFound ]*
|
// get : Dict k v, k -> Result v [ KeyNotFound ]*
|
||||||
let key_not_found = SolvedType::TagUnion(
|
let key_not_found = SolvedType::TagUnion(
|
||||||
vec![(TagName::Global("KeyNotFound".into()), vec![])],
|
vec![(TagName::Global("KeyNotFound".into()), vec![])],
|
||||||
Box::new(SolvedType::Wildcard),
|
Box::new(SolvedType::Wildcard),
|
||||||
);
|
);
|
||||||
|
|
||||||
add_type(
|
add_type(
|
||||||
Symbol::MAP_GET,
|
Symbol::DICT_GET,
|
||||||
top_level_function(
|
top_level_function(
|
||||||
vec![map_type(flex(TVAR1), flex(TVAR2)), flex(TVAR1)],
|
vec![dict_type(flex(TVAR1), flex(TVAR2)), flex(TVAR1)],
|
||||||
Box::new(result_type(flex(TVAR2), key_not_found)),
|
Box::new(result_type(flex(TVAR2), key_not_found)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
add_type(
|
add_type(
|
||||||
Symbol::MAP_INSERT,
|
Symbol::DICT_INSERT,
|
||||||
top_level_function(
|
top_level_function(
|
||||||
vec![map_type(flex(TVAR1), flex(TVAR2)), flex(TVAR1), flex(TVAR2)],
|
vec![
|
||||||
Box::new(map_type(flex(TVAR1), flex(TVAR2))),
|
dict_type(flex(TVAR1), flex(TVAR2)),
|
||||||
|
flex(TVAR1),
|
||||||
|
flex(TVAR2),
|
||||||
|
],
|
||||||
|
Box::new(dict_type(flex(TVAR1), flex(TVAR2))),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ pub fn uniq_stdlib() -> StdLib {
|
||||||
Symbol::ATTR_ATTR,
|
Symbol::ATTR_ATTR,
|
||||||
Symbol::LIST_LIST,
|
Symbol::LIST_LIST,
|
||||||
Symbol::SET_SET,
|
Symbol::SET_SET,
|
||||||
Symbol::MAP_MAP,
|
Symbol::DICT_DICT,
|
||||||
Symbol::STR_STR,
|
Symbol::STR_STR,
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -831,18 +831,18 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Map module
|
// Dict module
|
||||||
|
|
||||||
// empty : Attr * (Map k v)
|
// empty : Attr * (Dict k v)
|
||||||
add_type(Symbol::MAP_EMPTY, {
|
add_type(Symbol::DICT_EMPTY, {
|
||||||
let_tvars! { star, k , v };
|
let_tvars! { star, k , v };
|
||||||
map_type(star, k, v)
|
dict_type(star, k, v)
|
||||||
});
|
});
|
||||||
|
|
||||||
// singleton : k, v -> Attr * (Map k v)
|
// singleton : k, v -> Attr * (Dict k v)
|
||||||
add_type(Symbol::MAP_SINGLETON, {
|
add_type(Symbol::DICT_SINGLETON, {
|
||||||
let_tvars! { star, k , v };
|
let_tvars! { star, k , v };
|
||||||
unique_function(vec![flex(k), flex(v)], map_type(star, k, v))
|
unique_function(vec![flex(k), flex(v)], dict_type(star, k, v))
|
||||||
});
|
});
|
||||||
|
|
||||||
let key_not_found = SolvedType::Apply(
|
let key_not_found = SolvedType::Apply(
|
||||||
|
@ -856,10 +856,10 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
// get : Attr (* | u) (Map (Attr * key) (Attr u val))
|
// get : Attr (* | u) (Dict (Attr * key) (Attr u val))
|
||||||
// , Attr * key
|
// , Attr * key
|
||||||
// -> Attr * (Result (Attr u val) [ KeyNotFound ]*)
|
// -> Attr * (Result (Attr u val) [ KeyNotFound ]*)
|
||||||
add_type(Symbol::MAP_GET, {
|
add_type(Symbol::DICT_GET, {
|
||||||
let_tvars! { u, key, val, star1, star2, star3, star4 };
|
let_tvars! { u, key, val, star1, star2, star3, star4 };
|
||||||
|
|
||||||
unique_function(
|
unique_function(
|
||||||
|
@ -869,7 +869,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||||
vec![
|
vec![
|
||||||
container(star1, vec![u]),
|
container(star1, vec![u]),
|
||||||
SolvedType::Apply(
|
SolvedType::Apply(
|
||||||
Symbol::MAP_MAP,
|
Symbol::DICT_DICT,
|
||||||
vec![attr_type(star2, key), attr_type(u, val)],
|
vec![attr_type(star2, key), attr_type(u, val)],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -889,11 +889,11 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
// insert : Attr * (Map key value)
|
// insert : Attr * (Dict key value)
|
||||||
// , key
|
// , key
|
||||||
// , value
|
// , value
|
||||||
// , Attr * (Map key value)
|
// , Attr * (Dict key value)
|
||||||
add_type(Symbol::MAP_INSERT, {
|
add_type(Symbol::DICT_INSERT, {
|
||||||
let_tvars! { star1, star2, key, value };
|
let_tvars! { star1, star2, key, value };
|
||||||
|
|
||||||
unique_function(
|
unique_function(
|
||||||
|
@ -902,7 +902,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||||
Symbol::ATTR_ATTR,
|
Symbol::ATTR_ATTR,
|
||||||
vec![
|
vec![
|
||||||
flex(star1),
|
flex(star1),
|
||||||
SolvedType::Apply(Symbol::MAP_MAP, vec![flex(key), flex(value)]),
|
SolvedType::Apply(Symbol::DICT_DICT, vec![flex(key), flex(value)]),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
flex(key),
|
flex(key),
|
||||||
|
@ -912,7 +912,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||||
Symbol::ATTR_ATTR,
|
Symbol::ATTR_ATTR,
|
||||||
vec![
|
vec![
|
||||||
flex(star2),
|
flex(star2),
|
||||||
SolvedType::Apply(Symbol::MAP_MAP, vec![flex(key), flex(value)]),
|
SolvedType::Apply(Symbol::DICT_DICT, vec![flex(key), flex(value)]),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -1267,12 +1267,12 @@ fn set_type(u: VarId, a: VarId) -> SolvedType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn map_type(u: VarId, key: VarId, value: VarId) -> SolvedType {
|
fn dict_type(u: VarId, key: VarId, value: VarId) -> SolvedType {
|
||||||
SolvedType::Apply(
|
SolvedType::Apply(
|
||||||
Symbol::ATTR_ATTR,
|
Symbol::ATTR_ATTR,
|
||||||
vec![
|
vec![
|
||||||
flex(u),
|
flex(u),
|
||||||
SolvedType::Apply(Symbol::MAP_MAP, vec![flex(key), flex(value)]),
|
SolvedType::Apply(Symbol::DICT_DICT, vec![flex(key), flex(value)]),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,7 +158,7 @@ pub fn basic_type_from_layout<'ctx>(
|
||||||
Float64 => context.f64_type().as_basic_type_enum(),
|
Float64 => context.f64_type().as_basic_type_enum(),
|
||||||
Float32 => context.f32_type().as_basic_type_enum(),
|
Float32 => context.f32_type().as_basic_type_enum(),
|
||||||
Float16 => context.f16_type().as_basic_type_enum(),
|
Float16 => context.f16_type().as_basic_type_enum(),
|
||||||
Map(_, _) | EmptyMap => panic!("TODO layout_to_basic_type for Builtin::Map"),
|
Dict(_, _) | EmptyDict => panic!("TODO layout_to_basic_type for Builtin::Dict"),
|
||||||
Set(_) | EmptySet => panic!("TODO layout_to_basic_type for Builtin::Set"),
|
Set(_) | EmptySet => panic!("TODO layout_to_basic_type for Builtin::Set"),
|
||||||
List(_, _) | Str | EmptyStr => collection(context, ptr_bytes).into(),
|
List(_, _) | Str | EmptyStr => collection(context, ptr_bytes).into(),
|
||||||
EmptyList => BasicTypeEnum::StructType(collection(context, ptr_bytes)),
|
EmptyList => BasicTypeEnum::StructType(collection(context, ptr_bytes)),
|
||||||
|
|
|
@ -397,7 +397,7 @@ fn decrement_refcount_builtin<'a, 'ctx, 'env>(
|
||||||
}
|
}
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
Map(key_layout, value_layout) => {
|
Dict(key_layout, value_layout) => {
|
||||||
if key_layout.contains_refcounted() || value_layout.contains_refcounted() {
|
if key_layout.contains_refcounted() || value_layout.contains_refcounted() {
|
||||||
// TODO decrement all values
|
// TODO decrement all values
|
||||||
}
|
}
|
||||||
|
@ -498,7 +498,7 @@ fn increment_refcount_builtin<'a, 'ctx, 'env>(
|
||||||
}
|
}
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
Map(key_layout, value_layout) => {
|
Dict(key_layout, value_layout) => {
|
||||||
if key_layout.contains_refcounted() || value_layout.contains_refcounted() {
|
if key_layout.contains_refcounted() || value_layout.contains_refcounted() {
|
||||||
// TODO decrement all values
|
// TODO decrement all values
|
||||||
}
|
}
|
||||||
|
|
|
@ -1206,11 +1206,11 @@ mod gen_primitives {
|
||||||
|
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
||||||
Dict k v : [ Node NodeColor k v (Dict k v) (Dict k v), Empty ]
|
RedBlackTree k v : [ Node NodeColor k v (RedBlackTree k v) (RedBlackTree k v), Empty ]
|
||||||
|
|
||||||
Key k : Num k
|
Key k : Num k
|
||||||
|
|
||||||
insert : Key k, v, Dict (Key k) v -> Dict (Key k) v
|
insert : Key k, v, RedBlackTree (Key k) v -> RedBlackTree (Key k) v
|
||||||
insert = \key, value, dict ->
|
insert = \key, value, dict ->
|
||||||
when insertHelp key value dict is
|
when insertHelp key value dict is
|
||||||
Node Red k v l r ->
|
Node Red k v l r ->
|
||||||
|
@ -1219,7 +1219,7 @@ mod gen_primitives {
|
||||||
x ->
|
x ->
|
||||||
x
|
x
|
||||||
|
|
||||||
insertHelp : (Key k), v, Dict (Key k) v -> Dict (Key k) v
|
insertHelp : (Key k), v, RedBlackTree (Key k) v -> RedBlackTree (Key k) v
|
||||||
insertHelp = \key, value, dict ->
|
insertHelp = \key, value, dict ->
|
||||||
when dict is
|
when dict is
|
||||||
Empty ->
|
Empty ->
|
||||||
|
@ -1238,7 +1238,7 @@ mod gen_primitives {
|
||||||
GT ->
|
GT ->
|
||||||
balance nColor nKey nValue nLeft (insertHelp key value nRight)
|
balance nColor nKey nValue nLeft (insertHelp key value nRight)
|
||||||
|
|
||||||
balance : NodeColor, k, v, Dict k v, Dict k v -> Dict k v
|
balance : NodeColor, k, v, RedBlackTree k v, RedBlackTree k v -> RedBlackTree k v
|
||||||
balance = \color, key, value, left, right ->
|
balance = \color, key, value, left, right ->
|
||||||
when right is
|
when right is
|
||||||
Node Red rK rV rLeft rRight ->
|
Node Red rK rV rLeft rRight ->
|
||||||
|
@ -1267,7 +1267,7 @@ mod gen_primitives {
|
||||||
_ ->
|
_ ->
|
||||||
Node color key value left right
|
Node color key value left right
|
||||||
|
|
||||||
main : Dict I64 {}
|
main : RedBlackTree I64 {}
|
||||||
main =
|
main =
|
||||||
insert 0 {} Empty
|
insert 0 {} Empty
|
||||||
"#
|
"#
|
||||||
|
@ -1288,9 +1288,9 @@ mod gen_primitives {
|
||||||
|
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
||||||
Dict k : [ Node NodeColor k (Dict k) (Dict k), Empty ]
|
RedBlackTree k : [ Node NodeColor k (RedBlackTree k) (RedBlackTree k), Empty ]
|
||||||
|
|
||||||
# balance : NodeColor, k, Dict k, Dict k -> Dict k
|
# balance : NodeColor, k, RedBlackTree k, RedBlackTree k -> RedBlackTree k
|
||||||
balance = \color, key, left, right ->
|
balance = \color, key, left, right ->
|
||||||
when right is
|
when right is
|
||||||
Node Red rK rLeft rRight ->
|
Node Red rK rLeft rRight ->
|
||||||
|
@ -1308,7 +1308,7 @@ mod gen_primitives {
|
||||||
_ ->
|
_ ->
|
||||||
Empty
|
Empty
|
||||||
|
|
||||||
main : Dict I64
|
main : RedBlackTree I64
|
||||||
main =
|
main =
|
||||||
balance Red 0 Empty Empty
|
balance Red 0 Empty Empty
|
||||||
"#
|
"#
|
||||||
|
@ -1325,13 +1325,13 @@ mod gen_primitives {
|
||||||
r#"
|
r#"
|
||||||
app "test" provides [ main ] to "./platform"
|
app "test" provides [ main ] to "./platform"
|
||||||
|
|
||||||
Dict k : [ Node k (Dict k) (Dict k), Empty ]
|
RedBlackTree k : [ Node k (RedBlackTree k) (RedBlackTree k), Empty ]
|
||||||
|
|
||||||
balance : k, Dict k -> Dict k
|
balance : k, RedBlackTree k -> RedBlackTree k
|
||||||
balance = \key, left ->
|
balance = \key, left ->
|
||||||
Node key left Empty
|
Node key left Empty
|
||||||
|
|
||||||
main : Dict I64
|
main : RedBlackTree I64
|
||||||
main =
|
main =
|
||||||
balance 0 Empty
|
balance 0 Empty
|
||||||
"#
|
"#
|
||||||
|
@ -1357,9 +1357,9 @@ mod gen_primitives {
|
||||||
|
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
||||||
Dict k v : [ Node NodeColor k v (Dict k v) (Dict k v), Empty ]
|
RedBlackTree k v : [ Node NodeColor k v (RedBlackTree k v) (RedBlackTree k v), Empty ]
|
||||||
|
|
||||||
# balance : NodeColor, k, v, Dict k v, Dict k v -> Dict k v
|
# balance : NodeColor, k, v, RedBlackTree k v, RedBlackTree k v -> RedBlackTree k v
|
||||||
balance = \color, key, value, left, right ->
|
balance = \color, key, value, left, right ->
|
||||||
when right is
|
when right is
|
||||||
Node Red rK rV rLeft rRight ->
|
Node Red rK rV rLeft rRight ->
|
||||||
|
@ -1378,7 +1378,7 @@ mod gen_primitives {
|
||||||
_ ->
|
_ ->
|
||||||
Empty
|
Empty
|
||||||
|
|
||||||
main : Dict I64 I64
|
main : RedBlackTree I64 I64
|
||||||
main =
|
main =
|
||||||
balance Red 0 0 Empty Empty
|
balance Red 0 0 Empty Empty
|
||||||
"#
|
"#
|
||||||
|
@ -1397,9 +1397,9 @@ mod gen_primitives {
|
||||||
|
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
||||||
Dict k v : [ Node NodeColor k v (Dict k v) (Dict k v), Empty ]
|
RedBlackTree k v : [ Node NodeColor k v (RedBlackTree k v) (RedBlackTree k v), Empty ]
|
||||||
|
|
||||||
balance : NodeColor, k, v, Dict k v, Dict k v -> Dict k v
|
balance : NodeColor, k, v, RedBlackTree k v, RedBlackTree k v -> RedBlackTree k v
|
||||||
balance = \color, key, value, left, right ->
|
balance = \color, key, value, left, right ->
|
||||||
when right is
|
when right is
|
||||||
Node Red rK rV rLeft rRight ->
|
Node Red rK rV rLeft rRight ->
|
||||||
|
@ -1428,7 +1428,7 @@ mod gen_primitives {
|
||||||
_ ->
|
_ ->
|
||||||
Node color key value left right
|
Node color key value left right
|
||||||
|
|
||||||
main : Dict I64 I64
|
main : RedBlackTree I64 I64
|
||||||
main =
|
main =
|
||||||
balance Red 0 0 Empty Empty
|
balance Red 0 0 Empty Empty
|
||||||
"#
|
"#
|
||||||
|
|
|
@ -8,8 +8,8 @@ interface AStar
|
||||||
Model position :
|
Model position :
|
||||||
{ evaluated : Set position
|
{ evaluated : Set position
|
||||||
, openSet : Set position
|
, openSet : Set position
|
||||||
, costs : Map.Map position F64
|
, costs : Dict.Dict position F64
|
||||||
, cameFrom : Map.Map position position
|
, cameFrom : Dict.Dict position position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ initialModel : position -> Model position
|
||||||
initialModel = \start ->
|
initialModel = \start ->
|
||||||
{ evaluated : Set.empty
|
{ evaluated : Set.empty
|
||||||
, openSet : Set.singleton start
|
, openSet : Set.singleton start
|
||||||
, costs : Map.singleton start 0.0
|
, costs : Dict.singleton start 0.0
|
||||||
, cameFrom : Map.empty
|
, cameFrom : Dict.empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ cheapestOpen : (position -> F64), Model position -> Result position [ KeyNotFoun
|
||||||
cheapestOpen = \costFunction, model ->
|
cheapestOpen = \costFunction, model ->
|
||||||
|
|
||||||
folder = \position, resSmallestSoFar ->
|
folder = \position, resSmallestSoFar ->
|
||||||
when Map.get model.costs position is
|
when Dict.get model.costs position is
|
||||||
Err e ->
|
Err e ->
|
||||||
Err e
|
Err e
|
||||||
|
|
||||||
|
@ -47,9 +47,9 @@ cheapestOpen = \costFunction, model ->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
reconstructPath : Map position position, position -> List position
|
reconstructPath : Dict position position, position -> List position
|
||||||
reconstructPath = \cameFrom, goal ->
|
reconstructPath = \cameFrom, goal ->
|
||||||
when Map.get cameFrom goal is
|
when Dict.get cameFrom goal is
|
||||||
Err KeyNotFound ->
|
Err KeyNotFound ->
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
@ -58,9 +58,9 @@ reconstructPath = \cameFrom, goal ->
|
||||||
|
|
||||||
updateCost : position, position, Model position -> Model position
|
updateCost : position, position, Model position -> Model position
|
||||||
updateCost = \current, neighbour, model ->
|
updateCost = \current, neighbour, model ->
|
||||||
newCameFrom = Map.insert model.cameFrom neighbour current
|
newCameFrom = Dict.insert model.cameFrom neighbour current
|
||||||
|
|
||||||
newCosts = Map.insert model.costs neighbour distanceTo
|
newCosts = Dict.insert model.costs neighbour distanceTo
|
||||||
|
|
||||||
distanceTo = reconstructPath newCameFrom neighbour
|
distanceTo = reconstructPath newCameFrom neighbour
|
||||||
|> List.len
|
|> List.len
|
||||||
|
@ -68,7 +68,7 @@ updateCost = \current, neighbour, model ->
|
||||||
|
|
||||||
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
||||||
|
|
||||||
when Map.get model.costs neighbour is
|
when Dict.get model.costs neighbour is
|
||||||
Err KeyNotFound ->
|
Err KeyNotFound ->
|
||||||
newModel
|
newModel
|
||||||
|
|
||||||
|
|
|
@ -242,15 +242,15 @@ mod test_load {
|
||||||
"RBTree",
|
"RBTree",
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
interface RBTree exposes [ Dict, empty ] imports []
|
interface RBTree exposes [ RedBlackTree, empty ] imports []
|
||||||
|
|
||||||
# The color of a node. Leaves are considered Black.
|
# The color of a node. Leaves are considered Black.
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
||||||
Dict k v : [ Node NodeColor k v (Dict k v) (Dict k v), Empty ]
|
RedBlackTree k v : [ Node NodeColor k v (RedBlackTree k v) (RedBlackTree k v), Empty ]
|
||||||
|
|
||||||
# Create an empty dictionary.
|
# Create an empty dictionary.
|
||||||
empty : Dict k v
|
empty : RedBlackTree k v
|
||||||
empty =
|
empty =
|
||||||
Empty
|
Empty
|
||||||
"#
|
"#
|
||||||
|
@ -265,7 +265,7 @@ mod test_load {
|
||||||
imports [ RBTree ]
|
imports [ RBTree ]
|
||||||
provides [ main ] to blah
|
provides [ main ] to blah
|
||||||
|
|
||||||
empty : RBTree.Dict I64 I64
|
empty : RBTree.RedBlackTree I64 I64
|
||||||
empty = RBTree.empty
|
empty = RBTree.empty
|
||||||
|
|
||||||
main = empty
|
main = empty
|
||||||
|
@ -424,7 +424,7 @@ mod test_load {
|
||||||
hashmap! {
|
hashmap! {
|
||||||
"findPath" => "{ costFunction : position, position -> F64, end : position, moveFunction : position -> Set position, start : position } -> Result (List position) [ KeyNotFound ]*",
|
"findPath" => "{ costFunction : position, position -> F64, end : position, moveFunction : position -> Set position, start : position } -> Result (List position) [ KeyNotFound ]*",
|
||||||
"initialModel" => "position -> Model position",
|
"initialModel" => "position -> Model position",
|
||||||
"reconstructPath" => "Map position position, position -> List position",
|
"reconstructPath" => "Dict position position, position -> List position",
|
||||||
"updateCost" => "position, position, Model position -> Model position",
|
"updateCost" => "position, position, Model position -> Model position",
|
||||||
"cheapestOpen" => "(position -> F64), Model position -> Result position [ KeyNotFound ]*",
|
"cheapestOpen" => "(position -> F64), Model position -> Result position [ KeyNotFound ]*",
|
||||||
"astar" => "(position, position -> F64), (position -> Set position), position, Model position -> [ Err [ KeyNotFound ]*, Ok (List position) ]*",
|
"astar" => "(position, position -> F64), (position -> Set position), position, Model position -> [ Err [ KeyNotFound ]*, Ok (List position) ]*",
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl ModuleName {
|
||||||
pub const STR: &'static str = "Str";
|
pub const STR: &'static str = "Str";
|
||||||
pub const NUM: &'static str = "Num";
|
pub const NUM: &'static str = "Num";
|
||||||
pub const LIST: &'static str = "List";
|
pub const LIST: &'static str = "List";
|
||||||
pub const MAP: &'static str = "Map";
|
pub const DICT: &'static str = "Dict";
|
||||||
pub const SET: &'static str = "Set";
|
pub const SET: &'static str = "Set";
|
||||||
pub const RESULT: &'static str = "Result";
|
pub const RESULT: &'static str = "Result";
|
||||||
|
|
||||||
|
|
|
@ -835,13 +835,13 @@ define_builtins! {
|
||||||
0 RESULT_RESULT: "Result" imported // the Result.Result type alias
|
0 RESULT_RESULT: "Result" imported // the Result.Result type alias
|
||||||
1 RESULT_MAP: "map"
|
1 RESULT_MAP: "map"
|
||||||
}
|
}
|
||||||
6 MAP: "Map" => {
|
6 DICT: "Dict" => {
|
||||||
0 MAP_MAP: "Map" imported // the Map.Map type alias
|
0 DICT_DICT: "Dict" imported // the Dict.Dict type alias
|
||||||
1 MAP_AT_MAP: "@Map" // the Map.@Map private tag
|
1 DICT_AT_DICT: "@Dict" // the Dict.@Dict private tag
|
||||||
2 MAP_EMPTY: "empty"
|
2 DICT_EMPTY: "empty"
|
||||||
3 MAP_SINGLETON: "singleton"
|
3 DICT_SINGLETON: "singleton"
|
||||||
4 MAP_GET: "get"
|
4 DICT_GET: "get"
|
||||||
5 MAP_INSERT: "insert"
|
5 DICT_INSERT: "insert"
|
||||||
}
|
}
|
||||||
7 SET: "Set" => {
|
7 SET: "Set" => {
|
||||||
0 SET_SET: "Set" imported // the Set.Set type alias
|
0 SET_SET: "Set" imported // the Set.Set type alias
|
||||||
|
|
|
@ -317,12 +317,12 @@ pub enum Builtin<'a> {
|
||||||
Float32,
|
Float32,
|
||||||
Float16,
|
Float16,
|
||||||
Str,
|
Str,
|
||||||
Map(&'a Layout<'a>, &'a Layout<'a>),
|
Dict(&'a Layout<'a>, &'a Layout<'a>),
|
||||||
Set(&'a Layout<'a>),
|
Set(&'a Layout<'a>),
|
||||||
List(MemoryMode, &'a Layout<'a>),
|
List(MemoryMode, &'a Layout<'a>),
|
||||||
EmptyStr,
|
EmptyStr,
|
||||||
EmptyList,
|
EmptyList,
|
||||||
EmptyMap,
|
EmptyDict,
|
||||||
EmptySet,
|
EmptySet,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -667,8 +667,8 @@ impl<'a> Builtin<'a> {
|
||||||
|
|
||||||
/// Number of machine words in an empty one of these
|
/// Number of machine words in an empty one of these
|
||||||
pub const STR_WORDS: u32 = 2;
|
pub const STR_WORDS: u32 = 2;
|
||||||
pub const MAP_WORDS: u32 = 6;
|
pub const DICT_WORDS: u32 = 6;
|
||||||
pub const SET_WORDS: u32 = Builtin::MAP_WORDS; // Set is an alias for Map with {} for value
|
pub const SET_WORDS: u32 = Builtin::DICT_WORDS; // Set is an alias for Dict with {} for value
|
||||||
pub const LIST_WORDS: u32 = 2;
|
pub const LIST_WORDS: u32 = 2;
|
||||||
|
|
||||||
/// Layout of collection wrapper for List and Str - a struct of (pointer, length).
|
/// Layout of collection wrapper for List and Str - a struct of (pointer, length).
|
||||||
|
@ -693,7 +693,7 @@ impl<'a> Builtin<'a> {
|
||||||
Float32 => Builtin::F32_SIZE,
|
Float32 => Builtin::F32_SIZE,
|
||||||
Float16 => Builtin::F16_SIZE,
|
Float16 => Builtin::F16_SIZE,
|
||||||
Str | EmptyStr => Builtin::STR_WORDS * pointer_size,
|
Str | EmptyStr => Builtin::STR_WORDS * pointer_size,
|
||||||
Map(_, _) | EmptyMap => Builtin::MAP_WORDS * pointer_size,
|
Dict(_, _) | EmptyDict => Builtin::DICT_WORDS * pointer_size,
|
||||||
Set(_) | EmptySet => Builtin::SET_WORDS * pointer_size,
|
Set(_) | EmptySet => Builtin::SET_WORDS * pointer_size,
|
||||||
List(_, _) | EmptyList => Builtin::LIST_WORDS * pointer_size,
|
List(_, _) | EmptyList => Builtin::LIST_WORDS * pointer_size,
|
||||||
}
|
}
|
||||||
|
@ -718,7 +718,7 @@ impl<'a> Builtin<'a> {
|
||||||
Float32 => align_of::<f32>() as u32,
|
Float32 => align_of::<f32>() as u32,
|
||||||
Float16 => align_of::<i16>() as u32,
|
Float16 => align_of::<i16>() as u32,
|
||||||
Str | EmptyStr => pointer_size,
|
Str | EmptyStr => pointer_size,
|
||||||
Map(_, _) | EmptyMap => pointer_size,
|
Dict(_, _) | EmptyDict => pointer_size,
|
||||||
Set(_) | EmptySet => pointer_size,
|
Set(_) | EmptySet => pointer_size,
|
||||||
List(_, _) | EmptyList => pointer_size,
|
List(_, _) | EmptyList => pointer_size,
|
||||||
}
|
}
|
||||||
|
@ -729,8 +729,8 @@ impl<'a> Builtin<'a> {
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Int128 | Int64 | Int32 | Int16 | Int8 | Int1 | Float128 | Float64 | Float32
|
Int128 | Int64 | Int32 | Int16 | Int8 | Int1 | Float128 | Float64 | Float32
|
||||||
| Float16 | EmptyStr | EmptyMap | EmptyList | EmptySet => true,
|
| Float16 | EmptyStr | EmptyDict | EmptyList | EmptySet => true,
|
||||||
Str | Map(_, _) | Set(_) | List(_, _) => false,
|
Str | Dict(_, _) | Set(_) | List(_, _) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,13 +740,13 @@ impl<'a> Builtin<'a> {
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Int128 | Int64 | Int32 | Int16 | Int8 | Int1 | Float128 | Float64 | Float32
|
Int128 | Int64 | Int32 | Int16 | Int8 | Int1 | Float128 | Float64 | Float32
|
||||||
| Float16 | EmptyStr | EmptyMap | EmptyList | EmptySet => false,
|
| Float16 | EmptyStr | EmptyDict | EmptyList | EmptySet => false,
|
||||||
List(mode, element_layout) => match mode {
|
List(mode, element_layout) => match mode {
|
||||||
MemoryMode::Refcounted => true,
|
MemoryMode::Refcounted => true,
|
||||||
MemoryMode::Unique => element_layout.contains_refcounted(),
|
MemoryMode::Unique => element_layout.contains_refcounted(),
|
||||||
},
|
},
|
||||||
|
|
||||||
Str | Map(_, _) | Set(_) => true,
|
Str | Dict(_, _) | Set(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -447,9 +447,9 @@ mod test_reporting {
|
||||||
these names seem close though:
|
these names seem close though:
|
||||||
|
|
||||||
baz
|
baz
|
||||||
Map
|
|
||||||
Str
|
Str
|
||||||
main
|
main
|
||||||
|
F64
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -1374,7 +1374,7 @@ mod test_reporting {
|
||||||
Bool
|
Bool
|
||||||
F64
|
F64
|
||||||
Num
|
Num
|
||||||
Map
|
Set
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -1830,7 +1830,7 @@ mod test_reporting {
|
||||||
f
|
f
|
||||||
F64
|
F64
|
||||||
Num
|
Num
|
||||||
Map
|
Set
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -3534,8 +3534,8 @@ mod test_reporting {
|
||||||
|
|
||||||
Bool
|
Bool
|
||||||
Num
|
Num
|
||||||
Map
|
|
||||||
Set
|
Set
|
||||||
|
Str
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -3928,10 +3928,10 @@ mod test_reporting {
|
||||||
# The color of a node. Leaves are considered Black.
|
# The color of a node. Leaves are considered Black.
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
||||||
Dict k v : [ Node NodeColor k v (Dict k v) (Dict k v), Empty ]
|
RBTree k v : [ Node NodeColor k v (RBTree k v) (RBTree k v), Empty ]
|
||||||
|
|
||||||
# Create an empty dictionary.
|
# Create an empty dictionary.
|
||||||
empty : Dict k v
|
empty : RBTree k v
|
||||||
empty =
|
empty =
|
||||||
Empty
|
Empty
|
||||||
|
|
||||||
|
|
|
@ -2508,10 +2508,10 @@ mod solve_expr {
|
||||||
infer_eq_without_problem(
|
infer_eq_without_problem(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
Map.insert
|
Dict.insert
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Map a b, a, b -> Map a b",
|
"Dict a b, a, b -> Dict a b",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2592,9 +2592,9 @@ mod solve_expr {
|
||||||
infer_eq_without_problem(
|
infer_eq_without_problem(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
reconstructPath : Map position position, position -> List position
|
reconstructPath : Dict position position, position -> List position
|
||||||
reconstructPath = \cameFrom, goal ->
|
reconstructPath = \cameFrom, goal ->
|
||||||
when Map.get cameFrom goal is
|
when Dict.get cameFrom goal is
|
||||||
Err KeyNotFound ->
|
Err KeyNotFound ->
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
@ -2604,7 +2604,7 @@ mod solve_expr {
|
||||||
reconstructPath
|
reconstructPath
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Map position position, position -> List position",
|
"Dict position position, position -> List position",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3101,22 +3101,22 @@ mod solve_expr {
|
||||||
# The color of a node. Leaves are considered Black.
|
# The color of a node. Leaves are considered Black.
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
||||||
Dict k v : [ Node NodeColor k v (Dict k v) (Dict k v), Empty ]
|
RBTree k v : [ Node NodeColor k v (RBTree k v) (RBTree k v), Empty ]
|
||||||
|
|
||||||
# Create an empty dictionary.
|
# Create an empty dictionary.
|
||||||
empty : Dict k v
|
empty : RBTree k v
|
||||||
empty =
|
empty =
|
||||||
Empty
|
Empty
|
||||||
|
|
||||||
foo : Dict I64 I64
|
foo : RBTree I64 I64
|
||||||
foo = empty
|
foo = empty
|
||||||
|
|
||||||
main : Dict I64 I64
|
main : RBTree I64 I64
|
||||||
main =
|
main =
|
||||||
foo
|
foo
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Dict I64 I64",
|
"RBTree I64 I64",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3131,21 +3131,21 @@ mod solve_expr {
|
||||||
r#"
|
r#"
|
||||||
app "test" provides [ main ] to "./platform"
|
app "test" provides [ main ] to "./platform"
|
||||||
|
|
||||||
Dict k : [ Node k (Dict k), Empty ]
|
RBTree k : [ Node k (RBTree k), Empty ]
|
||||||
|
|
||||||
balance : Dict k -> Dict k
|
balance : RBTree k -> RBTree k
|
||||||
balance = \left ->
|
balance = \left ->
|
||||||
when left is
|
when left is
|
||||||
Node _ Empty -> Empty
|
Node _ Empty -> Empty
|
||||||
|
|
||||||
_ -> Empty
|
_ -> Empty
|
||||||
|
|
||||||
main : Dict {}
|
main : RBTree {}
|
||||||
main =
|
main =
|
||||||
balance Empty
|
balance Empty
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Dict {}",
|
"RBTree {}",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3158,9 +3158,9 @@ mod solve_expr {
|
||||||
|
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
||||||
Dict k v : [ Node NodeColor k v (Dict k v) (Dict k v), Empty ]
|
RBTree k v : [ Node NodeColor k v (RBTree k v) (RBTree k v), Empty ]
|
||||||
|
|
||||||
moveRedLeft : Dict k v -> Dict k v
|
moveRedLeft : RBTree k v -> RBTree k v
|
||||||
moveRedLeft = \dict ->
|
moveRedLeft = \dict ->
|
||||||
when dict is
|
when dict is
|
||||||
# Node clr k v (Node lClr lK lV lLeft lRight) (Node rClr rK rV ((Node Red rlK rlV rlL rlR) as rLeft) rRight) ->
|
# Node clr k v (Node lClr lK lV lLeft lRight) (Node rClr rK rV ((Node Red rlK rlV rlL rlR) as rLeft) rRight) ->
|
||||||
|
@ -3196,7 +3196,7 @@ mod solve_expr {
|
||||||
_ ->
|
_ ->
|
||||||
dict
|
dict
|
||||||
|
|
||||||
balance : NodeColor, k, v, Dict k v, Dict k v -> Dict k v
|
balance : NodeColor, k, v, RBTree k v, RBTree k v -> RBTree k v
|
||||||
balance = \color, key, value, left, right ->
|
balance = \color, key, value, left, right ->
|
||||||
when right is
|
when right is
|
||||||
Node Red rK rV rLeft rRight ->
|
Node Red rK rV rLeft rRight ->
|
||||||
|
@ -3228,7 +3228,7 @@ mod solve_expr {
|
||||||
|
|
||||||
Key k : Num k
|
Key k : Num k
|
||||||
|
|
||||||
removeHelpEQGT : Key k, Dict (Key k) v -> Dict (Key k) v
|
removeHelpEQGT : Key k, RBTree (Key k) v -> RBTree (Key k) v
|
||||||
removeHelpEQGT = \targetKey, dict ->
|
removeHelpEQGT = \targetKey, dict ->
|
||||||
when dict is
|
when dict is
|
||||||
Node color key value left right ->
|
Node color key value left right ->
|
||||||
|
@ -3245,7 +3245,7 @@ mod solve_expr {
|
||||||
Empty ->
|
Empty ->
|
||||||
Empty
|
Empty
|
||||||
|
|
||||||
getMin : Dict k v -> Dict k v
|
getMin : RBTree k v -> RBTree k v
|
||||||
getMin = \dict ->
|
getMin = \dict ->
|
||||||
when dict is
|
when dict is
|
||||||
# Node _ _ _ ((Node _ _ _ _ _) as left) _ ->
|
# Node _ _ _ ((Node _ _ _ _ _) as left) _ ->
|
||||||
|
@ -3258,7 +3258,7 @@ mod solve_expr {
|
||||||
dict
|
dict
|
||||||
|
|
||||||
|
|
||||||
moveRedRight : Dict k v -> Dict k v
|
moveRedRight : RBTree k v -> RBTree k v
|
||||||
moveRedRight = \dict ->
|
moveRedRight = \dict ->
|
||||||
when dict is
|
when dict is
|
||||||
Node clr k v (Node lClr lK lV (Node Red llK llV llLeft llRight) lRight) (Node rClr rK rV rLeft rRight) ->
|
Node clr k v (Node lClr lK lV (Node Red llK llV llLeft llRight) lRight) (Node rClr rK rV rLeft rRight) ->
|
||||||
|
@ -3291,7 +3291,7 @@ mod solve_expr {
|
||||||
dict
|
dict
|
||||||
|
|
||||||
|
|
||||||
removeHelpPrepEQGT : Key k, Dict (Key k) v, NodeColor, (Key k), v, Dict (Key k) v, Dict (Key k) v -> Dict (Key k) v
|
removeHelpPrepEQGT : Key k, RBTree (Key k) v, NodeColor, (Key k), v, RBTree (Key k) v, RBTree (Key k) v -> RBTree (Key k) v
|
||||||
removeHelpPrepEQGT = \_, dict, color, key, value, left, right ->
|
removeHelpPrepEQGT = \_, dict, color, key, value, left, right ->
|
||||||
when left is
|
when left is
|
||||||
Node Red lK lV lLeft lRight ->
|
Node Red lK lV lLeft lRight ->
|
||||||
|
@ -3314,7 +3314,7 @@ mod solve_expr {
|
||||||
dict
|
dict
|
||||||
|
|
||||||
|
|
||||||
removeMin : Dict k v -> Dict k v
|
removeMin : RBTree k v -> RBTree k v
|
||||||
removeMin = \dict ->
|
removeMin = \dict ->
|
||||||
when dict is
|
when dict is
|
||||||
Node color key value left right ->
|
Node color key value left right ->
|
||||||
|
@ -3342,7 +3342,7 @@ mod solve_expr {
|
||||||
_ ->
|
_ ->
|
||||||
Empty
|
Empty
|
||||||
|
|
||||||
removeHelp : Key k, Dict (Key k) v -> Dict (Key k) v
|
removeHelp : Key k, RBTree (Key k) v -> RBTree (Key k) v
|
||||||
removeHelp = \targetKey, dict ->
|
removeHelp = \targetKey, dict ->
|
||||||
when dict is
|
when dict is
|
||||||
Empty ->
|
Empty ->
|
||||||
|
@ -3370,12 +3370,12 @@ mod solve_expr {
|
||||||
removeHelpEQGT targetKey (removeHelpPrepEQGT targetKey dict color key value left right)
|
removeHelpEQGT targetKey (removeHelpPrepEQGT targetKey dict color key value left right)
|
||||||
|
|
||||||
|
|
||||||
main : Dict I64 I64
|
main : RBTree I64 I64
|
||||||
main =
|
main =
|
||||||
removeHelp 1 Empty
|
removeHelp 1 Empty
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Dict I64 I64",
|
"RBTree I64 I64",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3386,9 +3386,9 @@ mod solve_expr {
|
||||||
r#"
|
r#"
|
||||||
app "test" provides [ main ] to "./platform"
|
app "test" provides [ main ] to "./platform"
|
||||||
|
|
||||||
Dict k : [ Node k (Dict k) (Dict k), Empty ]
|
RBTree k : [ Node k (RBTree k) (RBTree k), Empty ]
|
||||||
|
|
||||||
removeHelp : Num k, Dict (Num k) -> Dict (Num k)
|
removeHelp : Num k, RBTree (Num k) -> RBTree (Num k)
|
||||||
removeHelp = \targetKey, dict ->
|
removeHelp = \targetKey, dict ->
|
||||||
when dict is
|
when dict is
|
||||||
Empty ->
|
Empty ->
|
||||||
|
@ -3410,12 +3410,12 @@ mod solve_expr {
|
||||||
Empty
|
Empty
|
||||||
|
|
||||||
|
|
||||||
main : Dict I64
|
main : RBTree I64
|
||||||
main =
|
main =
|
||||||
removeHelp 1 Empty
|
removeHelp 1 Empty
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Dict I64",
|
"RBTree I64",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3428,9 +3428,9 @@ mod solve_expr {
|
||||||
|
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
||||||
Dict k v : [ Node NodeColor k v (Dict k v) (Dict k v), Empty ]
|
RBTree k v : [ Node NodeColor k v (RBTree k v) (RBTree k v), Empty ]
|
||||||
|
|
||||||
removeHelp : Num k, Dict (Num k) v -> Dict (Num k) v
|
removeHelp : Num k, RBTree (Num k) v -> RBTree (Num k) v
|
||||||
removeHelp = \targetKey, dict ->
|
removeHelp = \targetKey, dict ->
|
||||||
when dict is
|
when dict is
|
||||||
Empty ->
|
Empty ->
|
||||||
|
@ -3459,13 +3459,13 @@ mod solve_expr {
|
||||||
|
|
||||||
Key k : Num k
|
Key k : Num k
|
||||||
|
|
||||||
balance : NodeColor, k, v, Dict k v, Dict k v -> Dict k v
|
balance : NodeColor, k, v, RBTree k v, RBTree k v -> RBTree k v
|
||||||
|
|
||||||
moveRedLeft : Dict k v -> Dict k v
|
moveRedLeft : RBTree k v -> RBTree k v
|
||||||
|
|
||||||
removeHelpPrepEQGT : Key k, Dict (Key k) v, NodeColor, (Key k), v, Dict (Key k) v, Dict (Key k) v -> Dict (Key k) v
|
removeHelpPrepEQGT : Key k, RBTree (Key k) v, NodeColor, (Key k), v, RBTree (Key k) v, RBTree (Key k) v -> RBTree (Key k) v
|
||||||
|
|
||||||
removeHelpEQGT : Key k, Dict (Key k) v -> Dict (Key k) v
|
removeHelpEQGT : Key k, RBTree (Key k) v -> RBTree (Key k) v
|
||||||
removeHelpEQGT = \targetKey, dict ->
|
removeHelpEQGT = \targetKey, dict ->
|
||||||
when dict is
|
when dict is
|
||||||
Node color key value left right ->
|
Node color key value left right ->
|
||||||
|
@ -3482,16 +3482,16 @@ mod solve_expr {
|
||||||
Empty ->
|
Empty ->
|
||||||
Empty
|
Empty
|
||||||
|
|
||||||
getMin : Dict k v -> Dict k v
|
getMin : RBTree k v -> RBTree k v
|
||||||
|
|
||||||
removeMin : Dict k v -> Dict k v
|
removeMin : RBTree k v -> RBTree k v
|
||||||
|
|
||||||
main : Dict I64 I64
|
main : RBTree I64 I64
|
||||||
main =
|
main =
|
||||||
removeHelp 1 Empty
|
removeHelp 1 Empty
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Dict I64 I64",
|
"RBTree I64 I64",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3540,18 +3540,18 @@ mod solve_expr {
|
||||||
r#"
|
r#"
|
||||||
app "test" provides [ main ] to "./platform"
|
app "test" provides [ main ] to "./platform"
|
||||||
|
|
||||||
Dict k : [ Node k (Dict k) (Dict k), Empty ]
|
RBTree k : [ Node k (RBTree k) (RBTree k), Empty ]
|
||||||
|
|
||||||
balance : k, Dict k -> Dict k
|
balance : k, RBTree k -> RBTree k
|
||||||
balance = \key, left ->
|
balance = \key, left ->
|
||||||
Node key left Empty
|
Node key left Empty
|
||||||
|
|
||||||
main : Dict I64
|
main : RBTree I64
|
||||||
main =
|
main =
|
||||||
balance 0 Empty
|
balance 0 Empty
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Dict I64",
|
"RBTree I64",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3562,20 +3562,20 @@ mod solve_expr {
|
||||||
r#"
|
r#"
|
||||||
app "test" provides [ main ] to "./platform"
|
app "test" provides [ main ] to "./platform"
|
||||||
|
|
||||||
Dict k : [ Node k (Dict k) (Dict k), Empty ]
|
RBTree k : [ Node k (RBTree k) (RBTree k), Empty ]
|
||||||
|
|
||||||
node = \x,y,z -> Node x y z
|
node = \x,y,z -> Node x y z
|
||||||
|
|
||||||
balance : k, Dict k -> Dict k
|
balance : k, RBTree k -> RBTree k
|
||||||
balance = \key, left ->
|
balance = \key, left ->
|
||||||
node key left Empty
|
node key left Empty
|
||||||
|
|
||||||
main : Dict I64
|
main : RBTree I64
|
||||||
main =
|
main =
|
||||||
balance 0 Empty
|
balance 0 Empty
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Dict I64",
|
"RBTree I64",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3588,9 +3588,9 @@ mod solve_expr {
|
||||||
|
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
||||||
Dict k v : [ Node NodeColor k v (Dict k v) (Dict k v), Empty ]
|
RBTree k v : [ Node NodeColor k v (RBTree k v) (RBTree k v), Empty ]
|
||||||
|
|
||||||
balance : NodeColor, k, v, Dict k v, Dict k v -> Dict k v
|
balance : NodeColor, k, v, RBTree k v, RBTree k v -> RBTree k v
|
||||||
balance = \color, key, value, left, right ->
|
balance = \color, key, value, left, right ->
|
||||||
when right is
|
when right is
|
||||||
Node Red rK rV rLeft rRight ->
|
Node Red rK rV rLeft rRight ->
|
||||||
|
@ -3619,12 +3619,12 @@ mod solve_expr {
|
||||||
_ ->
|
_ ->
|
||||||
Node color key value left right
|
Node color key value left right
|
||||||
|
|
||||||
main : Dict I64 I64
|
main : RBTree I64 I64
|
||||||
main =
|
main =
|
||||||
balance Red 0 0 Empty Empty
|
balance Red 0 0 Empty Empty
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Dict I64 I64",
|
"RBTree I64 I64",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3636,9 +3636,9 @@ mod solve_expr {
|
||||||
r#"
|
r#"
|
||||||
app Test provides [ main ] imports []
|
app Test provides [ main ] imports []
|
||||||
|
|
||||||
Dict k : [ Node k (Dict k) (Dict k), Empty ]
|
RBTree k : [ Node k (RBTree k) (RBTree k), Empty ]
|
||||||
|
|
||||||
balance : k, Dict k -> Dict k
|
balance : k, RBTree k -> RBTree k
|
||||||
balance = \key, left ->
|
balance = \key, left ->
|
||||||
when left is
|
when left is
|
||||||
Node _ _ lRight ->
|
Node _ _ lRight ->
|
||||||
|
@ -3648,12 +3648,12 @@ mod solve_expr {
|
||||||
Empty
|
Empty
|
||||||
|
|
||||||
|
|
||||||
main : Dict I64
|
main : RBTree I64
|
||||||
main =
|
main =
|
||||||
balance 0 Empty
|
balance 0 Empty
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Dict I64",
|
"RBTree I64",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2397,24 +2397,24 @@ mod solve_uniq_expr {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn map_empty() {
|
fn map_empty() {
|
||||||
infer_eq("Map.empty", "Attr * (Map * *)");
|
infer_eq("Dict.empty", "Attr * (Dict * *)");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn map_singelton() {
|
fn map_singelton() {
|
||||||
infer_eq("Map.singleton", "Attr * (a, b -> Attr * (Map a b))");
|
infer_eq("Dict.singleton", "Attr * (a, b -> Attr * (Dict a b))");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn map_get() {
|
fn map_get() {
|
||||||
infer_eq("Map.get", "Attr * (Attr (* | c) (Map (Attr * a) (Attr c b)), Attr * a -> Attr * (Result (Attr c b) (Attr * [ KeyNotFound ]*)))");
|
infer_eq("Dict.get", "Attr * (Attr (* | c) (Dict (Attr * a) (Attr c b)), Attr * a -> Attr * (Result (Attr c b) (Attr * [ KeyNotFound ]*)))");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn map_insert() {
|
fn map_insert() {
|
||||||
infer_eq(
|
infer_eq(
|
||||||
"Map.insert",
|
"Dict.insert",
|
||||||
"Attr * (Attr * (Map a b), a, b -> Attr * (Map a b))",
|
"Attr * (Attr * (Dict a b), a, b -> Attr * (Dict a b))",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2747,9 +2747,9 @@ mod solve_uniq_expr {
|
||||||
infer_eq(
|
infer_eq(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
reconstructPath : Map position position, position -> List position
|
reconstructPath : Dict position position, position -> List position
|
||||||
reconstructPath = \cameFrom, goal ->
|
reconstructPath = \cameFrom, goal ->
|
||||||
when Map.get cameFrom goal is
|
when Dict.get cameFrom goal is
|
||||||
Err KeyNotFound ->
|
Err KeyNotFound ->
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
@ -2759,7 +2759,7 @@ mod solve_uniq_expr {
|
||||||
reconstructPath
|
reconstructPath
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"Attr Shared (Attr Shared (Map (Attr * position) (Attr Shared position)), Attr Shared position -> Attr * (List (Attr Shared position)))"
|
"Attr Shared (Attr Shared (Dict (Attr * position) (Attr Shared position)), Attr Shared position -> Attr * (List (Attr Shared position)))"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2772,15 +2772,15 @@ mod solve_uniq_expr {
|
||||||
r#"
|
r#"
|
||||||
Model position : { evaluated : Set position
|
Model position : { evaluated : Set position
|
||||||
, openSet : Set position
|
, openSet : Set position
|
||||||
, costs : Map.Map position F64
|
, costs : Dict.Dict position F64
|
||||||
, cameFrom : Map.Map position position
|
, cameFrom : Dict.Dict position position
|
||||||
}
|
}
|
||||||
|
|
||||||
cheapestOpen : (position -> F64), Model position -> Result position [ KeyNotFound ]*
|
cheapestOpen : (position -> F64), Model position -> Result position [ KeyNotFound ]*
|
||||||
cheapestOpen = \costFunction, model ->
|
cheapestOpen = \costFunction, model ->
|
||||||
|
|
||||||
folder = \position, resSmallestSoFar ->
|
folder = \position, resSmallestSoFar ->
|
||||||
when Map.get model.costs position is
|
when Dict.get model.costs position is
|
||||||
Err e ->
|
Err e ->
|
||||||
Err e
|
Err e
|
||||||
|
|
||||||
|
@ -2815,13 +2815,13 @@ mod solve_uniq_expr {
|
||||||
r#"
|
r#"
|
||||||
Model position : { evaluated : Set position
|
Model position : { evaluated : Set position
|
||||||
, openSet : Set position
|
, openSet : Set position
|
||||||
, costs : Map.Map position F64
|
, costs : Dict.Dict position F64
|
||||||
, cameFrom : Map.Map position position
|
, cameFrom : Dict.Dict position position
|
||||||
}
|
}
|
||||||
|
|
||||||
reconstructPath : Map position position, position -> List position
|
reconstructPath : Dict position position, position -> List position
|
||||||
reconstructPath = \cameFrom, goal ->
|
reconstructPath = \cameFrom, goal ->
|
||||||
when Map.get cameFrom goal is
|
when Dict.get cameFrom goal is
|
||||||
Err KeyNotFound ->
|
Err KeyNotFound ->
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
@ -2830,9 +2830,9 @@ mod solve_uniq_expr {
|
||||||
|
|
||||||
updateCost : position, position, Model position -> Model position
|
updateCost : position, position, Model position -> Model position
|
||||||
updateCost = \current, neighbour, model ->
|
updateCost = \current, neighbour, model ->
|
||||||
newCameFrom = Map.insert model.cameFrom neighbour current
|
newCameFrom = Dict.insert model.cameFrom neighbour current
|
||||||
|
|
||||||
newCosts = Map.insert model.costs neighbour distanceTo
|
newCosts = Dict.insert model.costs neighbour distanceTo
|
||||||
|
|
||||||
distanceTo = reconstructPath newCameFrom neighbour
|
distanceTo = reconstructPath newCameFrom neighbour
|
||||||
|> List.len
|
|> List.len
|
||||||
|
@ -2840,7 +2840,7 @@ mod solve_uniq_expr {
|
||||||
|
|
||||||
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
||||||
|
|
||||||
when Map.get model.costs neighbour is
|
when Dict.get model.costs neighbour is
|
||||||
Err KeyNotFound ->
|
Err KeyNotFound ->
|
||||||
newModel
|
newModel
|
||||||
|
|
||||||
|
@ -2867,8 +2867,8 @@ mod solve_uniq_expr {
|
||||||
r#"
|
r#"
|
||||||
Model position : { evaluated : Set position
|
Model position : { evaluated : Set position
|
||||||
, openSet : Set position
|
, openSet : Set position
|
||||||
, costs : Map.Map position F64
|
, costs : Dict.Dict position F64
|
||||||
, cameFrom : Map.Map position position
|
, cameFrom : Dict.Dict position position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2876,8 +2876,8 @@ mod solve_uniq_expr {
|
||||||
initialModel = \start ->
|
initialModel = \start ->
|
||||||
{ evaluated : Set.empty
|
{ evaluated : Set.empty
|
||||||
, openSet : Set.singleton start
|
, openSet : Set.singleton start
|
||||||
, costs : Map.singleton start 0.0
|
, costs : Dict.singleton start 0.0
|
||||||
, cameFrom : Map.empty
|
, cameFrom : Dict.empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2885,7 +2885,7 @@ mod solve_uniq_expr {
|
||||||
cheapestOpen = \costFunction, model ->
|
cheapestOpen = \costFunction, model ->
|
||||||
|
|
||||||
folder = \position, resSmallestSoFar ->
|
folder = \position, resSmallestSoFar ->
|
||||||
when Map.get model.costs position is
|
when Dict.get model.costs position is
|
||||||
Err e ->
|
Err e ->
|
||||||
Err e
|
Err e
|
||||||
|
|
||||||
|
@ -2906,9 +2906,9 @@ mod solve_uniq_expr {
|
||||||
|> Result.map (\x -> x.position)
|
|> Result.map (\x -> x.position)
|
||||||
|
|
||||||
|
|
||||||
reconstructPath : Map position position, position -> List position
|
reconstructPath : Dict position position, position -> List position
|
||||||
reconstructPath = \cameFrom, goal ->
|
reconstructPath = \cameFrom, goal ->
|
||||||
when Map.get cameFrom goal is
|
when Dict.get cameFrom goal is
|
||||||
Err KeyNotFound ->
|
Err KeyNotFound ->
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
@ -2918,9 +2918,9 @@ mod solve_uniq_expr {
|
||||||
|
|
||||||
updateCost : position, position, Model position -> Model position
|
updateCost : position, position, Model position -> Model position
|
||||||
updateCost = \current, neighbour, model ->
|
updateCost = \current, neighbour, model ->
|
||||||
newCameFrom = Map.insert model.cameFrom neighbour current
|
newCameFrom = Dict.insert model.cameFrom neighbour current
|
||||||
|
|
||||||
newCosts = Map.insert model.costs neighbour distanceTo
|
newCosts = Dict.insert model.costs neighbour distanceTo
|
||||||
|
|
||||||
distanceTo =
|
distanceTo =
|
||||||
reconstructPath newCameFrom neighbour
|
reconstructPath newCameFrom neighbour
|
||||||
|
@ -2929,7 +2929,7 @@ mod solve_uniq_expr {
|
||||||
|
|
||||||
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
||||||
|
|
||||||
when Map.get model.costs neighbour is
|
when Dict.get model.costs neighbour is
|
||||||
Err KeyNotFound ->
|
Err KeyNotFound ->
|
||||||
newModel
|
newModel
|
||||||
|
|
||||||
|
|
|
@ -247,8 +247,8 @@ pub fn set_type(a: SolvedType) -> SolvedType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn map_type(key: SolvedType, value: SolvedType) -> SolvedType {
|
pub fn dict_type(key: SolvedType, value: SolvedType) -> SolvedType {
|
||||||
SolvedType::Apply(Symbol::MAP_MAP, vec![key, value])
|
SolvedType::Apply(Symbol::DICT_DICT, vec![key, value])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn single_private_tag(symbol: Symbol, type_arguments: Vec<SolvedType>) -> SolvedType {
|
fn single_private_tag(symbol: Symbol, type_arguments: Vec<SolvedType>) -> SolvedType {
|
||||||
|
|
|
@ -150,7 +150,7 @@ pub enum Type {
|
||||||
actual: Box<Type>,
|
actual: Box<Type>,
|
||||||
},
|
},
|
||||||
RecursiveTagUnion(Variable, Vec<(TagName, Vec<Type>)>, Box<Type>),
|
RecursiveTagUnion(Variable, Vec<(TagName, Vec<Type>)>, Box<Type>),
|
||||||
/// Applying a type to some arguments (e.g. Map.Map String Int)
|
/// Applying a type to some arguments (e.g. Dict.Dict String Int)
|
||||||
Apply(Symbol, Vec<Type>),
|
Apply(Symbol, Vec<Type>),
|
||||||
/// Boolean type used in uniqueness inference
|
/// Boolean type used in uniqueness inference
|
||||||
Boolean(boolean_algebra::Bool),
|
Boolean(boolean_algebra::Bool),
|
||||||
|
|
|
@ -48,7 +48,7 @@ fn main() {
|
||||||
generate(
|
generate(
|
||||||
vec![
|
vec![
|
||||||
PathBuf::from(r"../compiler/builtins/docs/Bool.roc"),
|
PathBuf::from(r"../compiler/builtins/docs/Bool.roc"),
|
||||||
PathBuf::from(r"../compiler/builtins/docs/Map.roc"),
|
PathBuf::from(r"../compiler/builtins/docs/Dict.roc"),
|
||||||
// Not working
|
// Not working
|
||||||
// PathBuf::from(r"../compiler/builtins/docs/List.roc"),
|
// PathBuf::from(r"../compiler/builtins/docs/List.roc"),
|
||||||
// Not working
|
// Not working
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue