Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tail recursion rewrite only works in specific case #31

Open
JustusAdam opened this issue Feb 7, 2019 · 3 comments
Open

Tail recursion rewrite only works in specific case #31

JustusAdam opened this issue Feb 7, 2019 · 3 comments

Comments

@JustusAdam
Copy link
Member

JustusAdam commented Feb 7, 2019

This whole rewriteCond and rewriteBranch algorithm is not correct. That is to say it only works in the specific case where a single if is the last expression in a recursive function. While the reason for this assumption is obvious we must consider that also nested if's technically are valid tail recursive functions so long as there is at least one branch that recurses and one branch that does not. I feel implementing this correctly however is going to require some effort, thus I think we should do so later.

@JustusAdam
Copy link
Member Author

Also currently the branches of that singular if only allow values and a recursive call. Not even let's are allowed.

@Feliix42
Copy link
Member

The following tail recursion algorithm does not work yet, although it sounds from your description like it should work:

ns some_ns;
use sf to::implement::{find_path, update_grid, is_empty};

fn main(maze: Maze, to_map: Vec<(Point, Point)>) -> Maze {
    let paths = for pair in to_map {
        find_path(maze, to_map)
    };

    let (remap_paths, new_maze) = update_grid(maze, paths);

    if (is_empty(remap_paths)) {
        new_maze
    } else {
        main(new_maze, remap_paths)
    }
}

The error says:

ohuac: Unsortable! (Probably due to a cycle)
CallStack (from HasCallStack):
  error, called at src/Universum/Debug.hs:60:11 in universum-1.2.0-6ylCZDYYoS898SMIz2iM8j:Universum.Debug
  error, called at src/hs/Ohua/Standalone.hs:301:22 in ohuac-0.3.0-8NKnqdddZODJ0p3a3pKPB3:Ohua.Standalone

Unfortunately, I am unable to provide ALang/DFLang dumps as the error is raised before these stages are processed.

@JustusAdam
Copy link
Member Author

This was tracked in ohua-dev/ohuac#17 and has been fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants