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

Reformat can't handle a file #2651

Open
spike7638 opened this issue Mar 31, 2021 · 0 comments
Open

Reformat can't handle a file #2651

spike7638 opened this issue Mar 31, 2021 · 0 comments
Labels
Printer things that have to do with turning an AST into Reason code

Comments

@spike7638
Copy link

spike7638 commented Mar 31, 2021

A student of mine wrote the attached code (which I've cleaned up a good deal to isolate the problem). He didn't realize that in an if-else expression returning a function, an INFIX function needs to be parenthesized, so he had this fragment:

let op = if (b) {<} else {>}

Once you put parens around the "<" and ">", everything's fine. Complete example appended here because I can't seem to attach a reasonML file.

===

type direction = L | R;
type path = list(direction);
type intTree = Leaf | Node(int, intTree, intTree);

let rec ammH: (intTree, list(direction), bool) => (path, int) =
  (inT, aloi, b) =>
  {
     let op = if (b) {<} else {>}

    switch (inT, aloi) {
    | (Leaf, _) => failwith("Tree cannot be empty")
    | (Node(x, Leaf, Leaf), direct) => (List.rev(direct), x)
    | (Node(_, Leaf, right), list) => ammH(right, [R, ...list], !b)
    | (Node(_, left, Leaf), list) => ammH(left, [L, ...list], !b)
    | (Node(_, Node(x1, x2, x3), Node(y1, y2, y3)), list) =>
      if ( op(x1, y1) ) {
        ammH(Node(x1, x2, x3), [L, ...list], !b);
      } else {
        ammH(Node(y1, y2, y3), [R, ...list], !b);
      }

    };
}

 let amm: intTree => (path, int) = intTree => ammH(intTree, [], false)
@davesnx davesnx added the Printer things that have to do with turning an AST into Reason code label Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Printer things that have to do with turning an AST into Reason code
Projects
None yet
Development

No branches or pull requests

2 participants