Changed Map to Dict in many tests

This commit is contained in:
Chadtech 2020-12-08 16:55:33 -05:00
parent 4dbd4fa893
commit b24933324a
6 changed files with 44 additions and 44 deletions

View file

@ -836,13 +836,13 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
// empty : Attr * (Map k v) // empty : Attr * (Map k v)
add_type(Symbol::DICT_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 * (Map k v)
add_type(Symbol::DICT_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(
@ -1267,7 +1267,7 @@ 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![

View file

@ -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) ]*",

View file

@ -628,7 +628,7 @@ 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 DICT_WORDS: u32 = 6; pub const DICT_WORDS: u32 = 6;
pub const SET_WORDS: u32 = Builtin::DICT_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).

View file

@ -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 ] CustomDict k v : [ Node NodeColor k v (CustomDict k v) (CustomDict k v), Empty ]
# Create an empty dictionary. # Create an empty dictionary.
empty : Dict k v empty : CustomDict k v
empty = empty =
Empty Empty
foo : Dict Int Int foo : CustomDict Int Int
foo = empty foo = empty
main : Dict Int Int main : CustomDict Int Int
main = main =
foo foo
"# "#
), ),
"Dict Int Int", "CustomDict Int Int",
); );
} }

View file

@ -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

View file

@ -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),