You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The text was updated successfully, but these errors were encountered:
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.
===
The text was updated successfully, but these errors were encountered: