mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
More progress
This commit is contained in:
parent
b56fbd38e1
commit
0edbf16d55
79 changed files with 1351 additions and 1419 deletions
|
@ -1,111 +1,99 @@
|
|||
interface AStar
|
||||
exposes [initialModel, reconstructPath, updateCost, cheapestOpen, astar, findPath]
|
||||
imports []
|
||||
|
||||
module [initial_model, reconstruct_path, update_cost, cheapest_open, astar, find_path]
|
||||
|
||||
# a port of https://github.com/krisajenkins/elm-astar/blob/2.1.3/src/AStar/Generalised.elm
|
||||
|
||||
Model position :
|
||||
{ evaluated : Set position
|
||||
, openSet : Set position
|
||||
, costs : Map.Map position F64
|
||||
, cameFrom : Map.Map position position
|
||||
}
|
||||
Model position : {
|
||||
evaluated : Set position,
|
||||
open_set : Set position,
|
||||
costs : Map.Map position F64,
|
||||
came_from : Map.Map position position,
|
||||
}
|
||||
|
||||
initial_model : position -> Model position
|
||||
initial_model = \start -> {
|
||||
evaluated: Set.empty({}),
|
||||
open_set: Set.single(start),
|
||||
costs: Dict.single(start, 0.0),
|
||||
came_from: Map.empty,
|
||||
}
|
||||
|
||||
initialModel : position -> Model position
|
||||
initialModel = \start ->
|
||||
{ evaluated : Set.empty {}
|
||||
, openSet : Set.single start
|
||||
, costs : Dict.single start 0.0
|
||||
, cameFrom : Map.empty
|
||||
}
|
||||
cheapest_open : (position -> F64), Model position -> Result position [KeyNotFound]*
|
||||
cheapest_open = \cost_function, model ->
|
||||
|
||||
folder = \res_smallest_so_far, position ->
|
||||
when Map.get(model.costs, position) is
|
||||
Err(e) ->
|
||||
Err(e)
|
||||
|
||||
cheapestOpen : (position -> F64), Model position -> Result position [KeyNotFound]*
|
||||
cheapestOpen = \costFunction, model ->
|
||||
Ok(cost) ->
|
||||
position_cost = cost_function(position)
|
||||
|
||||
folder = \resSmallestSoFar, position ->
|
||||
when Map.get model.costs position is
|
||||
Err e ->
|
||||
Err e
|
||||
when res_smallest_so_far is
|
||||
Err(_) -> Ok({ position, cost: cost + position_cost })
|
||||
Ok(smallest_so_far) ->
|
||||
if position_cost + cost < smallest_so_far.cost then
|
||||
Ok({ position, cost: cost + position_cost })
|
||||
else
|
||||
Ok(smallest_so_far)
|
||||
|
||||
Ok cost ->
|
||||
positionCost = costFunction position
|
||||
Set.walk(model.open_set, Err(KeyNotFound), folder)
|
||||
|> Result.map(\x -> x.position)
|
||||
|
||||
when resSmallestSoFar is
|
||||
Err _ -> Ok { position, cost: cost + positionCost }
|
||||
Ok smallestSoFar ->
|
||||
if positionCost + cost < smallestSoFar.cost then
|
||||
Ok { position, cost: cost + positionCost }
|
||||
|
||||
else
|
||||
Ok smallestSoFar
|
||||
|
||||
Set.walk model.openSet (Err KeyNotFound) folder
|
||||
|> Result.map (\x -> x.position)
|
||||
|
||||
|
||||
|
||||
reconstructPath : Map position position, position -> List position
|
||||
reconstructPath = \cameFrom, goal ->
|
||||
when Map.get cameFrom goal is
|
||||
Err KeyNotFound ->
|
||||
reconstruct_path : Map position position, position -> List position
|
||||
reconstruct_path = \came_from, goal ->
|
||||
when Map.get(came_from, goal) is
|
||||
Err(KeyNotFound) ->
|
||||
[]
|
||||
|
||||
Ok next ->
|
||||
List.append (reconstructPath cameFrom next) goal
|
||||
Ok(next) ->
|
||||
List.append(reconstruct_path(came_from, next), goal)
|
||||
|
||||
updateCost : position, position, Model position -> Model position
|
||||
updateCost = \current, neighbour, model ->
|
||||
newCameFrom = Map.insert model.cameFrom neighbour current
|
||||
update_cost : position, position, Model position -> Model position
|
||||
update_cost = \current, neighbour, model ->
|
||||
new_came_from = Map.insert(model.came_from, neighbour, current)
|
||||
|
||||
newCosts = Map.insert model.costs neighbour distanceTo
|
||||
new_costs = Map.insert(model.costs, neighbour, distance_to)
|
||||
|
||||
distanceTo = reconstructPath newCameFrom neighbour
|
||||
|> List.len
|
||||
|> Num.toFrac
|
||||
distance_to =
|
||||
reconstruct_path(new_came_from, neighbour)
|
||||
|> List.len
|
||||
|> Num.to_frac
|
||||
|
||||
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
||||
new_model = { model & costs: new_costs, came_from: new_came_from }
|
||||
|
||||
when Map.get model.costs neighbour is
|
||||
Err KeyNotFound ->
|
||||
newModel
|
||||
|
||||
Ok previousDistance ->
|
||||
if distanceTo < previousDistance then
|
||||
newModel
|
||||
when Map.get(model.costs, neighbour) is
|
||||
Err(KeyNotFound) ->
|
||||
new_model
|
||||
|
||||
Ok(previous_distance) ->
|
||||
if distance_to < previous_distance then
|
||||
new_model
|
||||
else
|
||||
model
|
||||
|
||||
|
||||
findPath : { costFunction: (position, position -> F64), moveFunction: (position -> Set position), start : position, end : position } -> Result (List position) [KeyNotFound]*
|
||||
findPath = \{ costFunction, moveFunction, start, end } ->
|
||||
astar costFunction moveFunction end (initialModel start)
|
||||
|
||||
find_path : { cost_function : position, position -> F64, move_function : position -> Set position, start : position, end : position } -> Result (List position) [KeyNotFound]*
|
||||
find_path = \{ cost_function, move_function, start, end } ->
|
||||
astar(cost_function, move_function, end, initial_model(start))
|
||||
|
||||
astar : (position, position -> F64), (position -> Set position), position, Model position -> [Err [KeyNotFound]*, Ok (List position)]*
|
||||
astar = \costFn, moveFn, goal, model ->
|
||||
when cheapestOpen (\position -> costFn goal position) model is
|
||||
Err _ ->
|
||||
Err KeyNotFound
|
||||
astar = \cost_fn, move_fn, goal, model ->
|
||||
when cheapest_open(\position -> cost_fn(goal, position), model) is
|
||||
Err(_) ->
|
||||
Err(KeyNotFound)
|
||||
|
||||
Ok current ->
|
||||
Ok(current) ->
|
||||
if current == goal then
|
||||
Ok (reconstructPath model.cameFrom goal)
|
||||
|
||||
Ok(reconstruct_path(model.came_from, goal))
|
||||
else
|
||||
model_popped = { model & open_set: Set.remove(model.open_set, current), evaluated: Set.insert(model.evaluated, current) }
|
||||
|
||||
modelPopped = { model & openSet : Set.remove model.openSet current, evaluated : Set.insert model.evaluated current }
|
||||
neighbours = move_fn(current)
|
||||
|
||||
neighbours = moveFn current
|
||||
new_neighbours = Set.difference(neighbours, model_popped.evaluated)
|
||||
|
||||
newNeighbours = Set.difference neighbours modelPopped.evaluated
|
||||
model_with_neighbours = { model_popped & open_set: Set.union(model_popped.open_set, new_neighbours) }
|
||||
|
||||
modelWithNeighbours = { modelPopped & openSet : Set.union modelPopped.openSet newNeighbours }
|
||||
model_with_costs = Set.walk(new_neighbours, model_with_neighbours, \md, nb -> update_cost(current, nb, md))
|
||||
|
||||
modelWithCosts = Set.walk newNeighbours modelWithNeighbours (\md, nb -> updateCost current nb md)
|
||||
|
||||
astar costFn moveFn goal modelWithCosts
|
||||
astar(cost_fn, move_fn, goal, model_with_costs)
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep1
|
||||
exposes [three, str, Unit, Identity, one, two]
|
||||
imports []
|
||||
module [three, str, Unit, Identity, one, two]
|
||||
|
||||
import Dep3Blah exposing [foo]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep2
|
||||
exposes [one, two, blah]
|
||||
imports []
|
||||
module [one, two, blah]
|
||||
|
||||
import Dep3Blah exposing [foo, bar]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep3Blah
|
||||
exposes [one, two, foo, bar]
|
||||
imports []
|
||||
module [one, two, foo, bar]
|
||||
|
||||
import Dep3Other
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep3Other
|
||||
exposes [foo, bar]
|
||||
imports []
|
||||
module [foo, bar]
|
||||
|
||||
foo = "foo from Dep3Other"
|
||||
bar = "bar from Dep3Other"
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface ImportAlias
|
||||
exposes [unit]
|
||||
imports []
|
||||
module [unit]
|
||||
|
||||
import Dep1
|
||||
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
interface ManualAttr
|
||||
exposes []
|
||||
imports []
|
||||
module []
|
||||
|
||||
# manually replicates the Attr wrapping that uniqueness inference uses, to try and find out why they are different
|
||||
# It is very important that there are no signatures here! elm uses an optimization that leads to less copying when
|
||||
# signatures are given.
|
||||
|
||||
map =
|
||||
unAttr = \Attr _ foobar -> foobar
|
||||
un_attr = \Attr(_, foobar) -> foobar
|
||||
|
||||
r = Attr unknown "bar"
|
||||
r = Attr(unknown, "bar")
|
||||
|
||||
s = Attr unknown2 { left : Attr Shared "foo" }
|
||||
s = Attr(unknown2, { left: Attr(Shared, "foo") })
|
||||
|
||||
when True is
|
||||
_ -> { y : r }
|
||||
_ -> { y : (unAttr s).left }
|
||||
_ -> { y: r }
|
||||
_ -> { y: (un_attr(s)).left }
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface OneDep
|
||||
exposes [str]
|
||||
imports []
|
||||
module [str]
|
||||
|
||||
import Dep3Blah exposing [foo]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Primary
|
||||
exposes [blah2, blah3, str, alwaysThree, identity, z, w, succeed, withDefault, yay]
|
||||
imports []
|
||||
module [blah2, blah3, str, always_three, identity, z, w, succeed, with_default, yay]
|
||||
|
||||
import Dep1
|
||||
import Dep2
|
||||
|
@ -12,24 +10,24 @@ blah3 = bar
|
|||
|
||||
str = Dep1.str
|
||||
|
||||
alwaysThree = \_ -> Dep1.three
|
||||
always_three = \_ -> Dep1.three
|
||||
|
||||
identity = \a -> a
|
||||
|
||||
z = identity (alwaysThree {})
|
||||
z = identity(always_three({}))
|
||||
|
||||
w : Dep1.Identity {}
|
||||
w = Identity {}
|
||||
w = Identity({})
|
||||
|
||||
succeed : a -> Dep1.Identity a
|
||||
succeed = \x -> Identity x
|
||||
succeed = \x -> Identity(x)
|
||||
|
||||
withDefault = Res.withDefault
|
||||
with_default = Res.with_default
|
||||
|
||||
yay : Res.Res {} err
|
||||
yay =
|
||||
ok = Ok "foo"
|
||||
ok = Ok("foo")
|
||||
|
||||
f = \_ -> {}
|
||||
|
||||
Res.map ok f
|
||||
Res.map(ok, f)
|
||||
|
|
|
@ -1,49 +1,46 @@
|
|||
app "quicksort" provides [swap, partition, partitionHelp, quicksort] to "./platform"
|
||||
app [swap, partition, partition_help, quicksort] {}
|
||||
|
||||
quicksort : List (Num a), U64, U64 -> List (Num a)
|
||||
quicksort = \list, low, high ->
|
||||
when partition low high list is
|
||||
Pair partitionIndex partitioned ->
|
||||
when partition(low, high, list) is
|
||||
Pair(partition_index, partitioned) ->
|
||||
partitioned
|
||||
|> quicksort low (partitionIndex - 1)
|
||||
|> quicksort (partitionIndex + 1) high
|
||||
|
||||
|> quicksort(low, (partition_index - 1))
|
||||
|> quicksort((partition_index + 1), high)
|
||||
|
||||
swap : U64, U64, List a -> List a
|
||||
swap = \i, j, list ->
|
||||
when Pair (List.get list i) (List.get list j) is
|
||||
Pair (Ok atI) (Ok atJ) ->
|
||||
when Pair(List.get(list, i), List.get(list, j)) is
|
||||
Pair(Ok(at_i), Ok(at_j)) ->
|
||||
list
|
||||
|> List.set i atJ
|
||||
|> List.set j atI
|
||||
|> List.set(i, at_j)
|
||||
|> List.set(j, at_i)
|
||||
|
||||
_ ->
|
||||
[]
|
||||
|
||||
|
||||
partition : U64, U64, List (Num a) -> [Pair U64 (List (Num a))]
|
||||
partition = \low, high, initialList ->
|
||||
when List.get initialList high is
|
||||
Ok pivot ->
|
||||
when partitionHelp (low - 1) low initialList high pivot is
|
||||
Pair newI newList ->
|
||||
Pair (newI + 1) (swap (newI + 1) high newList)
|
||||
partition = \low, high, initial_list ->
|
||||
when List.get(initial_list, high) is
|
||||
Ok(pivot) ->
|
||||
when partition_help((low - 1), low, initial_list, high, pivot) is
|
||||
Pair(new_i, new_list) ->
|
||||
Pair((new_i + 1), swap((new_i + 1), high, new_list))
|
||||
|
||||
Err _ ->
|
||||
Pair (low - 1) initialList
|
||||
Err(_) ->
|
||||
Pair((low - 1), initial_list)
|
||||
|
||||
|
||||
partitionHelp : U64, U64, List (Num a), U64, (Num a) -> [Pair U64 (List (Num a))]
|
||||
partitionHelp = \i, j, list, high, pivot ->
|
||||
partition_help : U64, U64, List (Num a), U64, Num a -> [Pair U64 (List (Num a))]
|
||||
partition_help = \i, j, list, high, pivot ->
|
||||
if j < high then
|
||||
when List.get list j is
|
||||
Ok value ->
|
||||
when List.get(list, j) is
|
||||
Ok(value) ->
|
||||
if value <= pivot then
|
||||
partitionHelp (i + 1) (j + 1) (swap (i + 1) j list) high pivot
|
||||
partition_help((i + 1), (j + 1), swap((i + 1), j, list), high, pivot)
|
||||
else
|
||||
partitionHelp i (j + 1) list high pivot
|
||||
partition_help(i, (j + 1), list, high, pivot)
|
||||
|
||||
Err _ ->
|
||||
Pair i list
|
||||
Err(_) ->
|
||||
Pair(i, list)
|
||||
else
|
||||
Pair i list
|
||||
Pair(i, list)
|
||||
|
|
|
@ -1,57 +1,53 @@
|
|||
app "quicksort" provides [quicksort] to "./platform"
|
||||
app [quicksort] {}
|
||||
|
||||
quicksortHelp : List (Num a), U64, U64 -> List (Num a)
|
||||
quicksortHelp = \list, low, high ->
|
||||
quicksort_help : List (Num a), U64, U64 -> List (Num a)
|
||||
quicksort_help = \list, low, high ->
|
||||
if low < high then
|
||||
when partition low high list is
|
||||
Pair partitionIndex partitioned ->
|
||||
when partition(low, high, list) is
|
||||
Pair(partition_index, partitioned) ->
|
||||
partitioned
|
||||
|> quicksortHelp low (partitionIndex - 1)
|
||||
|> quicksortHelp (partitionIndex + 1) high
|
||||
|> quicksort_help(low, (partition_index - 1))
|
||||
|> quicksort_help((partition_index + 1), high)
|
||||
else
|
||||
list
|
||||
|
||||
|
||||
swap : U64, U64, List a -> List a
|
||||
swap = \i, j, list ->
|
||||
when Pair (List.get list i) (List.get list j) is
|
||||
Pair (Ok atI) (Ok atJ) ->
|
||||
when Pair(List.get(list, i), List.get(list, j)) is
|
||||
Pair(Ok(at_i), Ok(at_j)) ->
|
||||
list
|
||||
|> List.set i atJ
|
||||
|> List.set j atI
|
||||
|> List.set(i, at_j)
|
||||
|> List.set(j, at_i)
|
||||
|
||||
_ ->
|
||||
[]
|
||||
|
||||
partition : U64, U64, List (Num a) -> [Pair U64 (List (Num a))]
|
||||
partition = \low, high, initialList ->
|
||||
when List.get initialList high is
|
||||
Ok pivot ->
|
||||
when partitionHelp (low - 1) low initialList high pivot is
|
||||
Pair newI newList ->
|
||||
Pair (newI + 1) (swap (newI + 1) high newList)
|
||||
partition = \low, high, initial_list ->
|
||||
when List.get(initial_list, high) is
|
||||
Ok(pivot) ->
|
||||
when partition_help((low - 1), low, initial_list, high, pivot) is
|
||||
Pair(new_i, new_list) ->
|
||||
Pair((new_i + 1), swap((new_i + 1), high, new_list))
|
||||
|
||||
Err _ ->
|
||||
Pair (low - 1) initialList
|
||||
Err(_) ->
|
||||
Pair((low - 1), initial_list)
|
||||
|
||||
|
||||
partitionHelp : U64, U64, List (Num a), U64, (Num a) -> [Pair U64 (List (Num a))]
|
||||
partitionHelp = \i, j, list, high, pivot ->
|
||||
partition_help : U64, U64, List (Num a), U64, Num a -> [Pair U64 (List (Num a))]
|
||||
partition_help = \i, j, list, high, pivot ->
|
||||
if j < high then
|
||||
when List.get list j is
|
||||
Ok value ->
|
||||
when List.get(list, j) is
|
||||
Ok(value) ->
|
||||
if value <= pivot then
|
||||
partitionHelp (i + 1) (j + 1) (swap (i + 1) j list) high pivot
|
||||
partition_help((i + 1), (j + 1), swap((i + 1), j, list), high, pivot)
|
||||
else
|
||||
partitionHelp i (j + 1) list high pivot
|
||||
partition_help(i, (j + 1), list, high, pivot)
|
||||
|
||||
Err _ ->
|
||||
Pair i list
|
||||
Err(_) ->
|
||||
Pair(i, list)
|
||||
else
|
||||
Pair i list
|
||||
Pair(i, list)
|
||||
|
||||
|
||||
|
||||
quicksort = \originalList ->
|
||||
n = List.len originalList
|
||||
quicksortHelp originalList 0 (n - 1)
|
||||
quicksort = \original_list ->
|
||||
n = List.len(original_list)
|
||||
quicksort_help(original_list, 0, (n - 1))
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
interface Records
|
||||
exposes [intVal]
|
||||
imports []
|
||||
module [int_val]
|
||||
|
||||
intVal =
|
||||
int_val =
|
||||
foo = \{ x } -> x
|
||||
|
||||
foo { x: 5 }
|
||||
foo({ x: 5 })
|
||||
|
|
|
@ -1,31 +1,29 @@
|
|||
interface Res
|
||||
exposes [Res, withDefault, map, andThen, ConsList]
|
||||
imports []
|
||||
module [Res, with_default, map, and_then, ConsList]
|
||||
|
||||
Res ok err : [Ok ok, Err err]
|
||||
|
||||
ConsList a : [Cons a (ConsList a), Nil]
|
||||
|
||||
listMap : ConsList a, (a -> b) -> ConsList b
|
||||
listMap = \list, f ->
|
||||
when list is
|
||||
Nil -> Nil
|
||||
Cons x xs -> Cons (f x) (listMap xs f)
|
||||
list_map : ConsList a, (a -> b) -> ConsList b
|
||||
list_map = \list, f ->
|
||||
when list is
|
||||
Nil -> Nil
|
||||
Cons(x, xs) -> Cons(f(x), list_map(xs, f))
|
||||
|
||||
map : Res a err, (a -> b) -> Res b err
|
||||
map = \result, transform ->
|
||||
when result is
|
||||
Ok ok -> Ok (transform ok)
|
||||
Err err -> Err err
|
||||
Ok(ok) -> Ok(transform(ok))
|
||||
Err(err) -> Err(err)
|
||||
|
||||
withDefault : Res a err, a -> a
|
||||
withDefault = \result, default ->
|
||||
with_default : Res a err, a -> a
|
||||
with_default = \result, default ->
|
||||
when result is
|
||||
Ok ok -> ok
|
||||
Err _ -> default
|
||||
Ok(ok) -> ok
|
||||
Err(_) -> default
|
||||
|
||||
andThen : Res a err, (a -> Res b err) -> Res b err
|
||||
andThen = \result, transform ->
|
||||
and_then : Res a err, (a -> Res b err) -> Res b err
|
||||
and_then = \result, transform ->
|
||||
when result is
|
||||
Ok ok -> transform ok
|
||||
Err err -> Err err
|
||||
Ok(ok) -> transform(ok)
|
||||
Err(err) -> Err(err)
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
interface WithBuiltins
|
||||
exposes [floatTest, divisionFn, divisionTest, intTest, constantNum, fromDep2, divDep1ByDep2]
|
||||
imports []
|
||||
module [float_test, division_fn, division_test, int_test, constant_num, from_dep2, div_dep1_by_dep2]
|
||||
|
||||
import Dep1
|
||||
import Dep2 exposing [two]
|
||||
|
||||
floatTest = Num.maxF64
|
||||
float_test = Num.max_f64
|
||||
|
||||
divisionFn = Num.div
|
||||
division_fn = Num.div
|
||||
|
||||
x = 5.0
|
||||
|
||||
divisionTest = Num.maxF64 / x
|
||||
division_test = Num.max_f64 / x
|
||||
|
||||
intTest = Num.maxI64
|
||||
int_test = Num.max_i64
|
||||
|
||||
constantNum = 5
|
||||
constant_num = 5
|
||||
|
||||
fromDep2 = Dep2.two
|
||||
from_dep2 = Dep2.two
|
||||
|
||||
divDep1ByDep2 = Dep1.three / fromDep2
|
||||
div_dep1_by_dep2 = Dep1.three / from_dep2
|
||||
|
|
|
@ -1,111 +1,99 @@
|
|||
interface AStar
|
||||
exposes [initialModel, reconstructPath, updateCost, cheapestOpen, astar, findPath]
|
||||
imports []
|
||||
|
||||
module [initial_model, reconstruct_path, update_cost, cheapest_open, astar, find_path]
|
||||
|
||||
# a port of https://github.com/krisajenkins/elm-astar/blob/2.1.3/src/AStar/Generalised.elm
|
||||
|
||||
Model position :
|
||||
{ evaluated : Set position
|
||||
, openSet : Set position
|
||||
, costs : Dict.Dict position F64
|
||||
, cameFrom : Dict.Dict position position
|
||||
}
|
||||
Model position : {
|
||||
evaluated : Set position,
|
||||
open_set : Set position,
|
||||
costs : Dict.Dict position F64,
|
||||
came_from : Dict.Dict position position,
|
||||
}
|
||||
|
||||
initial_model : position -> Model position where position implements Hash & Eq
|
||||
initial_model = \start -> {
|
||||
evaluated: Set.empty({}),
|
||||
open_set: Set.single(start),
|
||||
costs: Dict.single(start, 0.0),
|
||||
came_from: Dict.empty({}),
|
||||
}
|
||||
|
||||
initialModel : position -> Model position where position implements Hash & Eq
|
||||
initialModel = \start ->
|
||||
{ evaluated : Set.empty {}
|
||||
, openSet : Set.single start
|
||||
, costs : Dict.single start 0.0
|
||||
, cameFrom : Dict.empty {}
|
||||
}
|
||||
cheapest_open : (position -> F64), Model position -> Result position [KeyNotFound] where position implements Hash & Eq
|
||||
cheapest_open = \cost_function, model ->
|
||||
|
||||
folder = \res_smallest_so_far, position ->
|
||||
when Dict.get(model.costs, position) is
|
||||
Err(e) ->
|
||||
Err(e)
|
||||
|
||||
cheapestOpen : (position -> F64), Model position -> Result position [KeyNotFound] where position implements Hash & Eq
|
||||
cheapestOpen = \costFunction, model ->
|
||||
Ok(cost) ->
|
||||
position_cost = cost_function(position)
|
||||
|
||||
folder = \resSmallestSoFar, position ->
|
||||
when Dict.get model.costs position is
|
||||
Err e ->
|
||||
Err e
|
||||
when res_smallest_so_far is
|
||||
Err(_) -> Ok({ position, cost: cost + position_cost })
|
||||
Ok(smallest_so_far) ->
|
||||
if position_cost + cost < smallest_so_far.cost then
|
||||
Ok({ position, cost: cost + position_cost })
|
||||
else
|
||||
Ok(smallest_so_far)
|
||||
|
||||
Ok cost ->
|
||||
positionCost = costFunction position
|
||||
Set.walk(model.open_set, Err(KeyNotFound), folder)
|
||||
|> Result.map(\x -> x.position)
|
||||
|
||||
when resSmallestSoFar is
|
||||
Err _ -> Ok { position, cost: cost + positionCost }
|
||||
Ok smallestSoFar ->
|
||||
if positionCost + cost < smallestSoFar.cost then
|
||||
Ok { position, cost: cost + positionCost }
|
||||
|
||||
else
|
||||
Ok smallestSoFar
|
||||
|
||||
Set.walk model.openSet (Err KeyNotFound) folder
|
||||
|> Result.map (\x -> x.position)
|
||||
|
||||
|
||||
|
||||
reconstructPath : Dict position position, position -> List position where position implements Hash & Eq
|
||||
reconstructPath = \cameFrom, goal ->
|
||||
when Dict.get cameFrom goal is
|
||||
Err KeyNotFound ->
|
||||
reconstruct_path : Dict position position, position -> List position where position implements Hash & Eq
|
||||
reconstruct_path = \came_from, goal ->
|
||||
when Dict.get(came_from, goal) is
|
||||
Err(KeyNotFound) ->
|
||||
[]
|
||||
|
||||
Ok next ->
|
||||
List.append (reconstructPath cameFrom next) goal
|
||||
Ok(next) ->
|
||||
List.append(reconstruct_path(came_from, next), goal)
|
||||
|
||||
updateCost : position, position, Model position -> Model position where position implements Hash & Eq
|
||||
updateCost = \current, neighbour, model ->
|
||||
newCameFrom = Dict.insert model.cameFrom neighbour current
|
||||
update_cost : position, position, Model position -> Model position where position implements Hash & Eq
|
||||
update_cost = \current, neighbour, model ->
|
||||
new_came_from = Dict.insert(model.came_from, neighbour, current)
|
||||
|
||||
newCosts = Dict.insert model.costs neighbour distanceTo
|
||||
new_costs = Dict.insert(model.costs, neighbour, distance_to)
|
||||
|
||||
distanceTo = reconstructPath newCameFrom neighbour
|
||||
|> List.len
|
||||
|> Num.toFrac
|
||||
distance_to =
|
||||
reconstruct_path(new_came_from, neighbour)
|
||||
|> List.len
|
||||
|> Num.to_frac
|
||||
|
||||
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
||||
new_model = { model & costs: new_costs, came_from: new_came_from }
|
||||
|
||||
when Dict.get model.costs neighbour is
|
||||
Err KeyNotFound ->
|
||||
newModel
|
||||
|
||||
Ok previousDistance ->
|
||||
if distanceTo < previousDistance then
|
||||
newModel
|
||||
when Dict.get(model.costs, neighbour) is
|
||||
Err(KeyNotFound) ->
|
||||
new_model
|
||||
|
||||
Ok(previous_distance) ->
|
||||
if distance_to < previous_distance then
|
||||
new_model
|
||||
else
|
||||
model
|
||||
|
||||
|
||||
findPath : { costFunction: (position, position -> F64), moveFunction: (position -> Set position), start : position, end : position } -> Result (List position) [KeyNotFound] where position implements Hash & Eq
|
||||
findPath = \{ costFunction, moveFunction, start, end } ->
|
||||
astar costFunction moveFunction end (initialModel start)
|
||||
|
||||
find_path : { cost_function : position, position -> F64, move_function : position -> Set position, start : position, end : position } -> Result (List position) [KeyNotFound] where position implements Hash & Eq
|
||||
find_path = \{ cost_function, move_function, start, end } ->
|
||||
astar(cost_function, move_function, end, initial_model(start))
|
||||
|
||||
astar : (position, position -> F64), (position -> Set position), position, Model position -> [Err [KeyNotFound], Ok (List position)] where position implements Hash & Eq
|
||||
astar = \costFn, moveFn, goal, model ->
|
||||
when cheapestOpen (\position -> costFn goal position) model is
|
||||
Err _ ->
|
||||
Err KeyNotFound
|
||||
astar = \cost_fn, move_fn, goal, model ->
|
||||
when cheapest_open(\position -> cost_fn(goal, position), model) is
|
||||
Err(_) ->
|
||||
Err(KeyNotFound)
|
||||
|
||||
Ok current ->
|
||||
Ok(current) ->
|
||||
if current == goal then
|
||||
Ok (reconstructPath model.cameFrom goal)
|
||||
|
||||
Ok(reconstruct_path(model.came_from, goal))
|
||||
else
|
||||
model_popped = { model & open_set: Set.remove(model.open_set, current), evaluated: Set.insert(model.evaluated, current) }
|
||||
|
||||
modelPopped = { model & openSet : Set.remove model.openSet current, evaluated : Set.insert model.evaluated current }
|
||||
neighbours = move_fn(current)
|
||||
|
||||
neighbours = moveFn current
|
||||
new_neighbours = Set.difference(neighbours, model_popped.evaluated)
|
||||
|
||||
newNeighbours = Set.difference neighbours modelPopped.evaluated
|
||||
model_with_neighbours = { model_popped & open_set: Set.union(model_popped.open_set, new_neighbours) }
|
||||
|
||||
modelWithNeighbours = { modelPopped & openSet : Set.union modelPopped.openSet newNeighbours }
|
||||
model_with_costs = Set.walk(new_neighbours, model_with_neighbours, \md, nb -> update_cost(current, nb, md))
|
||||
|
||||
modelWithCosts = Set.walk newNeighbours modelWithNeighbours (\md, nb -> updateCost current nb md)
|
||||
|
||||
astar costFn moveFn goal modelWithCosts
|
||||
astar(cost_fn, move_fn, goal, model_with_costs)
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep1
|
||||
exposes [three, str, Unit, Identity, one, two]
|
||||
imports []
|
||||
module [three, str, Unit, Identity, one, two]
|
||||
|
||||
import Dep3 exposing [foo]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep2
|
||||
exposes [one, two, blah]
|
||||
imports []
|
||||
module [one, two, blah]
|
||||
|
||||
import Dep3 exposing [foo, bar]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep3
|
||||
exposes [one, two, foo, bar]
|
||||
imports []
|
||||
module [one, two, foo, bar]
|
||||
|
||||
one = 1
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
interface ExposedUsedOutsideScope exposes [good, bad] imports []
|
||||
module [good, bad]
|
||||
|
||||
good =
|
||||
import Dep2 exposing [two]
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface ImportAlias
|
||||
exposes [unit]
|
||||
imports []
|
||||
module [unit]
|
||||
|
||||
import Dep1
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
interface ImportInsideDef exposes [dep1Str, dep2TwoDobuled] imports []
|
||||
module [dep1_str, dep2_two_dobuled]
|
||||
|
||||
dep1Str =
|
||||
dep1_str =
|
||||
import Dep1
|
||||
Dep1.str
|
||||
|
||||
dep2TwoDobuled =
|
||||
dep2_two_dobuled =
|
||||
2
|
||||
* (
|
||||
import Dep2 exposing [two]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
interface ImportUsedOutsideScope exposes [good, bad] imports []
|
||||
module [good, bad]
|
||||
|
||||
good =
|
||||
import Dep2
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface IngestedFile
|
||||
exposes [str, nested]
|
||||
imports []
|
||||
module [str, nested]
|
||||
|
||||
import "IngestedFile.roc" as foo : Str
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
interface IngestedFileBytes
|
||||
exposes [str]
|
||||
imports []
|
||||
module [str]
|
||||
|
||||
import "IngestedFileBytes.roc" as foo : List U8
|
||||
|
||||
str = Str.fromUtf8 foo |> Result.withDefault ""
|
||||
str = Str.from_utf8(foo) |> Result.with_default("")
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
interface ManualAttr
|
||||
exposes []
|
||||
imports []
|
||||
module []
|
||||
|
||||
# manually replicates the Attr wrapping that uniqueness inference uses, to try and find out why they are different
|
||||
# It is very important that there are no signatures here! elm uses an optimization that leads to less copying when
|
||||
# signatures are given.
|
||||
|
||||
map =
|
||||
unAttr = \Attr _ foobar -> foobar
|
||||
un_attr = \Attr(_, foobar) -> foobar
|
||||
|
||||
r = Attr unknown "bar"
|
||||
r = Attr(unknown, "bar")
|
||||
|
||||
s = Attr unknown2 { left : Attr Shared "foo" }
|
||||
s = Attr(unknown2, { left: Attr(Shared, "foo") })
|
||||
|
||||
when True is
|
||||
_ -> { y : r }
|
||||
_ -> { y : (unAttr s).left }
|
||||
_ -> { y: r }
|
||||
_ -> { y: (un_attr(s)).left }
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface OneDep
|
||||
exposes [str]
|
||||
imports []
|
||||
module [str]
|
||||
|
||||
import Dep3 exposing [foo]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Primary
|
||||
exposes [blah2, blah3, str, alwaysThree, identity, z, w, succeed, withDefault, yay]
|
||||
imports []
|
||||
module [blah2, blah3, str, always_three, identity, z, w, succeed, with_default, yay]
|
||||
|
||||
import Dep1
|
||||
import Dep2
|
||||
|
@ -12,24 +10,24 @@ blah3 = bar
|
|||
|
||||
str = Dep1.str
|
||||
|
||||
alwaysThree = \_ -> Dep1.three
|
||||
always_three = \_ -> Dep1.three
|
||||
|
||||
identity = \a -> a
|
||||
|
||||
z = identity (alwaysThree {})
|
||||
z = identity(always_three({}))
|
||||
|
||||
w : Dep1.Identity {}
|
||||
w = Identity {}
|
||||
w = Identity({})
|
||||
|
||||
succeed : a -> Dep1.Identity a
|
||||
succeed = \x -> Identity x
|
||||
succeed = \x -> Identity(x)
|
||||
|
||||
withDefault = Res.withDefault
|
||||
with_default = Res.with_default
|
||||
|
||||
yay : Res.Res {} err
|
||||
yay =
|
||||
ok = Ok "foo"
|
||||
ok = Ok("foo")
|
||||
|
||||
f = \_ -> {}
|
||||
|
||||
Res.map ok f
|
||||
Res.map(ok, f)
|
||||
|
|
|
@ -1,51 +1,46 @@
|
|||
interface Quicksort
|
||||
exposes [swap, partition, quicksort]
|
||||
imports []
|
||||
module [swap, partition, quicksort]
|
||||
|
||||
quicksort : List (Num a), U64, U64 -> List (Num a)
|
||||
quicksort = \list, low, high ->
|
||||
when partition low high list is
|
||||
Pair partitionIndex partitioned ->
|
||||
when partition(low, high, list) is
|
||||
Pair(partition_index, partitioned) ->
|
||||
partitioned
|
||||
|> quicksort low (partitionIndex - 1)
|
||||
|> quicksort (partitionIndex + 1) high
|
||||
|
||||
|> quicksort(low, (partition_index - 1))
|
||||
|> quicksort((partition_index + 1), high)
|
||||
|
||||
swap : U64, U64, List a -> List a
|
||||
swap = \i, j, list ->
|
||||
when Pair (List.get list i) (List.get list j) is
|
||||
Pair (Ok atI) (Ok atJ) ->
|
||||
when Pair(List.get(list, i), List.get(list, j)) is
|
||||
Pair(Ok(at_i), Ok(at_j)) ->
|
||||
list
|
||||
|> List.set i atJ
|
||||
|> List.set j atI
|
||||
|> List.set(i, at_j)
|
||||
|> List.set(j, at_i)
|
||||
|
||||
_ ->
|
||||
[]
|
||||
|
||||
|
||||
partition : U64, U64, List (Num a) -> [Pair U64 (List (Num a))]
|
||||
partition = \low, high, initialList ->
|
||||
when List.get initialList high is
|
||||
Ok pivot ->
|
||||
when partitionHelp (low - 1) low initialList high pivot is
|
||||
Pair newI newList ->
|
||||
Pair (newI + 1) (swap (newI + 1) high newList)
|
||||
partition = \low, high, initial_list ->
|
||||
when List.get(initial_list, high) is
|
||||
Ok(pivot) ->
|
||||
when partition_help((low - 1), low, initial_list, high, pivot) is
|
||||
Pair(new_i, new_list) ->
|
||||
Pair((new_i + 1), swap((new_i + 1), high, new_list))
|
||||
|
||||
Err _ ->
|
||||
Pair (low - 1) initialList
|
||||
Err(_) ->
|
||||
Pair((low - 1), initial_list)
|
||||
|
||||
|
||||
partitionHelp : U64, U64, List (Num a), U64, (Num a) -> [Pair U64 (List (Num a))]
|
||||
partitionHelp = \i, j, list, high, pivot ->
|
||||
partition_help : U64, U64, List (Num a), U64, Num a -> [Pair U64 (List (Num a))]
|
||||
partition_help = \i, j, list, high, pivot ->
|
||||
if j < high then
|
||||
when List.get list j is
|
||||
Ok value ->
|
||||
when List.get(list, j) is
|
||||
Ok(value) ->
|
||||
if value <= pivot then
|
||||
partitionHelp (i + 1) (j + 1) (swap (i + 1) j list) high pivot
|
||||
partition_help((i + 1), (j + 1), swap((i + 1), j, list), high, pivot)
|
||||
else
|
||||
partitionHelp i (j + 1) list high pivot
|
||||
partition_help(i, (j + 1), list, high, pivot)
|
||||
|
||||
Err _ ->
|
||||
Pair i list
|
||||
Err(_) ->
|
||||
Pair(i, list)
|
||||
else
|
||||
Pair i list
|
||||
Pair(i, list)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
interface Records
|
||||
exposes [intVal]
|
||||
imports []
|
||||
module [int_val]
|
||||
|
||||
intVal =
|
||||
int_val =
|
||||
foo = \{ x } -> x
|
||||
|
||||
foo { x: 5 }
|
||||
foo({ x: 5 })
|
||||
|
|
|
@ -1,31 +1,29 @@
|
|||
interface Res
|
||||
exposes [Res, withDefault, map, listMap, andThen, ConsList]
|
||||
imports []
|
||||
module [Res, with_default, map, list_map, and_then, ConsList]
|
||||
|
||||
Res ok err : [Ok ok, Err err]
|
||||
|
||||
ConsList a : [Cons a (ConsList a), Nil]
|
||||
|
||||
listMap : ConsList a, (a -> b) -> ConsList b
|
||||
listMap = \list, f ->
|
||||
when list is
|
||||
Nil -> Nil
|
||||
Cons x xs -> Cons (f x) (listMap xs f)
|
||||
list_map : ConsList a, (a -> b) -> ConsList b
|
||||
list_map = \list, f ->
|
||||
when list is
|
||||
Nil -> Nil
|
||||
Cons(x, xs) -> Cons(f(x), list_map(xs, f))
|
||||
|
||||
map : Res a err, (a -> b) -> Res b err
|
||||
map = \result, transform ->
|
||||
when result is
|
||||
Ok ok -> Ok (transform ok)
|
||||
Err err -> Err err
|
||||
Ok(ok) -> Ok(transform(ok))
|
||||
Err(err) -> Err(err)
|
||||
|
||||
withDefault : Res a err, a -> a
|
||||
withDefault = \result, default ->
|
||||
with_default : Res a err, a -> a
|
||||
with_default = \result, default ->
|
||||
when result is
|
||||
Ok ok -> ok
|
||||
Err _ -> default
|
||||
Ok(ok) -> ok
|
||||
Err(_) -> default
|
||||
|
||||
andThen : Res a err, (a -> Res b err) -> Res b err
|
||||
andThen = \result, transform ->
|
||||
and_then : Res a err, (a -> Res b err) -> Res b err
|
||||
and_then = \result, transform ->
|
||||
when result is
|
||||
Ok ok -> transform ok
|
||||
Err err -> Err err
|
||||
Ok(ok) -> transform(ok)
|
||||
Err(err) -> Err(err)
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
interface WithBuiltins
|
||||
exposes [floatTest, divisionFn, divisionTest, intTest, constantNum, fromDep2, divDep1ByDep2]
|
||||
imports []
|
||||
module [float_test, division_fn, division_test, int_test, constant_num, from_dep2, div_dep1_by_dep2]
|
||||
|
||||
import Dep1
|
||||
import Dep2
|
||||
|
||||
floatTest = Num.maxF64
|
||||
float_test = Num.max_f64
|
||||
|
||||
divisionFn = Num.div
|
||||
division_fn = Num.div
|
||||
|
||||
x = 5.0
|
||||
|
||||
divisionTest = Num.maxF64 / x
|
||||
division_test = Num.max_f64 / x
|
||||
|
||||
intTest = Num.maxI64
|
||||
int_test = Num.max_i64
|
||||
|
||||
constantNum = 5
|
||||
constant_num = 5
|
||||
|
||||
fromDep2 = Dep2.two
|
||||
from_dep2 = Dep2.two
|
||||
|
||||
divDep1ByDep2 = Dep1.three / fromDep2
|
||||
div_dep1_by_dep2 = Dep1.three / from_dep2
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
## An interface for docs tests
|
||||
interface Docs
|
||||
exposes [makeUser, getNameExposed]
|
||||
imports []
|
||||
module [make_user, get_name_exposed]
|
||||
|
||||
## This is a user
|
||||
User : { name : Str }
|
||||
|
@ -9,12 +7,12 @@ User : { name : Str }
|
|||
## Makes a user
|
||||
##
|
||||
## Takes a name Str.
|
||||
makeUser : Str -> User
|
||||
makeUser = \name ->
|
||||
make_user : Str -> User
|
||||
make_user = \name ->
|
||||
{ name }
|
||||
|
||||
## Gets the user's name
|
||||
getName = \a -> a.name
|
||||
get_name = \a -> a.name
|
||||
|
||||
getNameExposed = getName
|
||||
get_name_exposed = get_name
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface MissingDep
|
||||
exposes [unit]
|
||||
imports []
|
||||
module [unit]
|
||||
|
||||
import ThisFileIsMissing
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface MissingIngestedFile
|
||||
exposes [unit]
|
||||
imports []
|
||||
module [unit]
|
||||
|
||||
import "ThisFileIsMissing" as data : List U8
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
interface Principal
|
||||
exposes [identity, intVal]
|
||||
imports []
|
||||
module [identity, int_val]
|
||||
|
||||
identity = \a -> a
|
||||
|
||||
intVal = identity "hi"
|
||||
int_val = identity("hi")
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Unit
|
||||
exposes [unit]
|
||||
imports []
|
||||
module [unit]
|
||||
|
||||
Unit : [Unit]
|
||||
|
||||
|
|
|
@ -512,11 +512,11 @@ fn load_docs() {
|
|||
(None, Some("An interface for docs tests\n")),
|
||||
(Some("User"), Some("This is a user\n")),
|
||||
(
|
||||
Some("makeUser"),
|
||||
Some("make_user"),
|
||||
Some("Makes a user\n\nTakes a name Str.\n"),
|
||||
),
|
||||
(Some("getName"), Some("Gets the user's name\n")),
|
||||
(Some("getNameExposed"), None),
|
||||
(Some("get_name"), Some("Gets the user's name\n")),
|
||||
(Some("get_name_exposed"), None),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(ident_str_opt, doc_str_opt)| {
|
||||
|
@ -553,8 +553,8 @@ fn import_inside_def() {
|
|||
expect_types(
|
||||
loaded_module,
|
||||
hashmap! {
|
||||
"dep1Str" => "Str",
|
||||
"dep2TwoDobuled" => "Frac *",
|
||||
"dep1_str" => "Str",
|
||||
"dep2_two_dobuled" => "Frac *",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -585,15 +585,15 @@ fn test_load_and_typecheck() {
|
|||
expect_types(
|
||||
loaded_module,
|
||||
hashmap! {
|
||||
"floatTest" => "F64",
|
||||
"divisionFn" => "Frac a, Frac a -> Frac a",
|
||||
"float_test" => "F64",
|
||||
"division_fn" => "Frac a, Frac a -> Frac a",
|
||||
"x" => "Frac *",
|
||||
"divisionTest" => "F64",
|
||||
"intTest" => "I64",
|
||||
"constantNum" => "Num *",
|
||||
"divisionTest" => "F64",
|
||||
"divDep1ByDep2" => "Frac a",
|
||||
"fromDep2" => "Frac a",
|
||||
"division_test" => "F64",
|
||||
"int_test" => "I64",
|
||||
"constant_num" => "Num *",
|
||||
"division_test" => "F64",
|
||||
"div_dep1_by_dep2" => "Frac a",
|
||||
"from_dep2" => "Frac a",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -608,7 +608,7 @@ fn iface_quicksort() {
|
|||
hashmap! {
|
||||
"swap" => "U64, U64, List a -> List a",
|
||||
"partition" => "U64, U64, List (Num a) -> [Pair U64 (List (Num a))]",
|
||||
"partitionHelp" => "U64, U64, List (Num a), U64, Num a -> [Pair U64 (List (Num a))]",
|
||||
"partition_help" => "U64, U64, List (Num a), U64, Num a -> [Pair U64 (List (Num a))]",
|
||||
"quicksort" => "List (Num a), U64, U64 -> List (Num a)",
|
||||
},
|
||||
);
|
||||
|
@ -622,11 +622,11 @@ fn load_astar() {
|
|||
expect_types(
|
||||
loaded_module,
|
||||
hashmap! {
|
||||
"findPath" => "{ costFunction : position, position -> F64, end : position, moveFunction : position -> Set position, start : position } -> Result (List position) [KeyNotFound] where position implements Hash & Eq",
|
||||
"initialModel" => "position -> Model position where position implements Hash & Eq",
|
||||
"reconstructPath" => "Dict position position, position -> List position where position implements Hash & Eq",
|
||||
"updateCost" => "position, position, Model position -> Model position where position implements Hash & Eq",
|
||||
"cheapestOpen" => "(position -> F64), Model position -> Result position [KeyNotFound] where position implements Hash & Eq",
|
||||
"find_path" => "{ cost_function : position, position -> F64, end : position, move_function : position -> Set position, start : position } -> Result (List position) [KeyNotFound] where position implements Hash & Eq",
|
||||
"initial_model" => "position -> Model position where position implements Hash & Eq",
|
||||
"reconstruct_path" => "Dict position position, position -> List position where position implements Hash & Eq",
|
||||
"update_cost" => "position, position, Model position -> Model position where position implements Hash & Eq",
|
||||
"cheapest_open" => "(position -> F64), Model position -> Result position [KeyNotFound] where position implements Hash & Eq",
|
||||
"astar" => "(position, position -> F64), (position -> Set position), position, Model position -> [Err [KeyNotFound], Ok (List position)] where position implements Hash & Eq",
|
||||
},
|
||||
);
|
||||
|
@ -640,7 +640,7 @@ fn load_principal_types() {
|
|||
expect_types(
|
||||
loaded_module,
|
||||
hashmap! {
|
||||
"intVal" => "Str",
|
||||
"int_val" => "Str",
|
||||
"identity" => "a -> a",
|
||||
},
|
||||
);
|
||||
|
@ -657,13 +657,13 @@ fn iface_dep_types() {
|
|||
"blah2" => "Frac *",
|
||||
"blah3" => "Str",
|
||||
"str" => "Str",
|
||||
"alwaysThree" => "* -> Frac *",
|
||||
"always_three" => "* -> Frac *",
|
||||
"identity" => "a -> a",
|
||||
"z" => "Frac *",
|
||||
"w" => "Dep1.Identity {}",
|
||||
"succeed" => "a -> Dep1.Identity a",
|
||||
"yay" => "Res.Res {} err",
|
||||
"withDefault" => "Res.Res a err, a -> a",
|
||||
"with_default" => "Res.Res a err, a -> a",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -679,13 +679,13 @@ fn app_dep_types() {
|
|||
"blah2" => "Frac *",
|
||||
"blah3" => "Str",
|
||||
"str" => "Str",
|
||||
"alwaysThree" => "* -> Frac *",
|
||||
"always_three" => "* -> Frac *",
|
||||
"identity" => "a -> a",
|
||||
"z" => "Frac *",
|
||||
"w" => "Dep1.Identity {}",
|
||||
"succeed" => "a -> Dep1.Identity a",
|
||||
"yay" => "Res.Res {} err",
|
||||
"withDefault" => "Res.Res a err, a -> a",
|
||||
"with_default" => "Res.Res a err, a -> a",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -897,13 +897,13 @@ fn opaque_wrapped_unwrapped_outside_defining_module() {
|
|||
"Main.roc",
|
||||
indoc!(
|
||||
r"
|
||||
module [twenty, readAge]
|
||||
module [twenty, read_age]
|
||||
|
||||
import Age exposing [Age]
|
||||
|
||||
twenty = @Age 20
|
||||
|
||||
readAge = \@Age n -> n
|
||||
read_age = \@Age n -> n
|
||||
"
|
||||
),
|
||||
),
|
||||
|
@ -933,8 +933,8 @@ fn opaque_wrapped_unwrapped_outside_defining_module() {
|
|||
|
||||
The unwrapped opaque type Age referenced here:
|
||||
|
||||
7│ readAge = \@Age n -> n
|
||||
^^^^
|
||||
7│ read_age = \@Age n -> n
|
||||
^^^^
|
||||
|
||||
is imported from another module:
|
||||
|
||||
|
@ -997,27 +997,27 @@ fn unused_imports() {
|
|||
"Main.roc",
|
||||
indoc!(
|
||||
r#"
|
||||
module [usedModule, unusedModule, unusedExposed, usingThreeValue, unusedWithAlias]
|
||||
module [used_module, unused_module, unused_exposed, using_three_value, unused_with_alias]
|
||||
|
||||
import Dep1
|
||||
import Dep3 exposing [Three]
|
||||
|
||||
usedModule =
|
||||
used_module =
|
||||
import Dep2
|
||||
Dep2.two
|
||||
|
||||
unusedModule =
|
||||
unused_module =
|
||||
import Dep2
|
||||
2
|
||||
|
||||
unusedExposed =
|
||||
unused_exposed =
|
||||
import Dep2 exposing [two]
|
||||
2
|
||||
|
||||
usingThreeValue =
|
||||
using_three_value =
|
||||
Dep3.three
|
||||
|
||||
unusedWithAlias =
|
||||
unused_with_alias =
|
||||
import Dep2 as D2
|
||||
2
|
||||
"#
|
||||
|
@ -1191,13 +1191,13 @@ fn explicit_builtin_type_import() {
|
|||
r#"
|
||||
interface Main exposes [main] imports []
|
||||
|
||||
import Dict exposing [Dict, isEmpty]
|
||||
import Dict exposing [Dict, is_empty]
|
||||
|
||||
myDict : Dict * *
|
||||
myDict =
|
||||
my_dict : Dict * *
|
||||
my_dict =
|
||||
Dict.empty {}
|
||||
|
||||
main = isEmpty myDict
|
||||
main = is_empty my_dict
|
||||
"#
|
||||
),
|
||||
)];
|
||||
|
@ -1210,7 +1210,7 @@ fn explicit_builtin_type_import() {
|
|||
|
||||
`Dict.Dict` was imported here:
|
||||
|
||||
3│ import Dict exposing [Dict, isEmpty]
|
||||
3│ import Dict exposing [Dict, is_empty]
|
||||
^^^^
|
||||
|
||||
All types from builtins are automatically exposed, so you can remove
|
||||
|
@ -1490,9 +1490,9 @@ fn alias_using_builtin_name() {
|
|||
"BoolExtra.roc",
|
||||
indoc!(
|
||||
r"
|
||||
interface BoolExtra exposes [toNum] imports []
|
||||
interface BoolExtra exposes [to_num] imports []
|
||||
|
||||
toNum = \value ->
|
||||
to_num = \value ->
|
||||
if value then 1 else 0
|
||||
"
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue