abilities syntax has -> implements

This commit is contained in:
Bryce Miller 2023-05-24 21:30:16 -04:00
parent 91e37293a2
commit dbc0204532
No known key found for this signature in database
GPG key ID: F1E97BF8DF152350
21 changed files with 89 additions and 84 deletions

View file

@ -10,9 +10,9 @@ Model position : {
openSet : Set position,
costs : Dict position F64,
cameFrom : Dict position position,
} | position has Hash & Eq
} | position implements Hash & Eq
initialModel : position -> Model position | position has Hash & Eq
initialModel : position -> Model position | position implements Hash & Eq
initialModel = \start -> {
evaluated: Set.empty {},
openSet: Set.single start,
@ -20,7 +20,7 @@ initialModel = \start -> {
cameFrom: Dict.empty {},
}
cheapestOpen : (position -> F64), Model position -> Result position {} | position has Hash & Eq
cheapestOpen : (position -> F64), Model position -> Result position {} | position implements Hash & Eq
cheapestOpen = \costFn, model ->
model.openSet
|> Set.toList
@ -35,13 +35,13 @@ cheapestOpen = \costFn, model ->
|> Result.map .position
|> Result.mapErr (\_ -> {})
reconstructPath : Dict position position, position -> List position | position has Hash & Eq
reconstructPath : Dict position position, position -> List position | position implements Hash & Eq
reconstructPath = \cameFrom, goal ->
when Dict.get cameFrom goal is
Err _ -> []
Ok next -> List.append (reconstructPath cameFrom next) goal
updateCost : position, position, Model position -> Model position | position has Hash & Eq
updateCost : position, position, Model position -> Model position | position implements Hash & Eq
updateCost = \current, neighbor, model ->
newCameFrom =
Dict.insert model.cameFrom neighbor current
@ -70,7 +70,7 @@ updateCost = \current, neighbor, model ->
else
model
astar : (position, position -> F64), (position -> Set position), position, Model position -> Result (List position) {} | position has Hash & Eq
astar : (position, position -> F64), (position -> Set position), position, Model position -> Result (List position) {} | position implements Hash & Eq
astar = \costFn, moveFn, goal, model ->
when cheapestOpen (\source -> costFn source goal) model is
Err {} -> Err {}