The following piece of code uses recursion to emulate a loop that keeps some local state (the maze):
ns some_ns;
use sf crate::{is_not_empty, splitup, join, insert_path, get_one, add_to, empty_vec};
use sf labyrinth::grid::update_maze;
use sf labyrinth::pathfinder::find_path;
fn main(maze: Maze, to_map: Vec<(Point, Point)>) -> Maze {
transact(maze, to_map)
}
fn search_path(maze: Maze, to_map: Vec<(Point, Point)>, mapped: Vec<Option<Path>>) -> Vec<Option<Path>> {
let (pair, tail) = get_one(to_map);
let p = find_path(maze, pair);
let updated = insert_path(p, maze);
let new_mapped = add_to(mapped, p);
if (is_not_empty(tail)) {
search_path(updated, tail, new_mapped)
} else {
new_mapped
}
}
fn transact(maze: Maze, to_map: Vec<(Point, Point)>) -> Maze {
let (tm1, tm2) = splitup(to_map);
let part1 = search_path(maze, tm1, empty_vec());
let part2 = search_path(maze, tm2, empty_vec());
let paths = join(part1, part2);
let (remap_paths, new_maze) = update_maze(maze, paths);
// simple check for len == 0
if (is_not_empty(remap_paths)) {
transact(new_maze, remap_paths)
} else {
new_maze
}
}
When compiling it using the latest version of both ohuac and ohua-core, I receive the following error, indicating that an error occured during dflang generation:
[Error] Rebinding of Binding "j"
CallStack (from HasCallStack):
throwErrorS, called at src/Ohua/Util.hs:225:20 in ohua-core-0.3.0-96ePW2cHQzLLYHDgUMVZet:Ohua.Util
throwErrorDebugS, called at src/Ohua/Monad.hs:43:12 in ohua-core-0.3.0-96ePW2cHQzLLYHDgUMVZet:Ohua.Monad
failWith, called at src/Ohua/DFLang/Passes.hs:58:23 in ohua-core-0.3.0-96ePW2cHQzLLYHDgUMVZet:Ohua.DFLang.Passes
The following piece of code uses recursion to emulate a loop that keeps some local state (the
maze
):When compiling it using the latest version of both
ohuac
andohua-core
, I receive the following error, indicating that an error occured during dflang generation:[alang-core] - [alang-resolved] - [dflang-core]