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
Given the post order program, demanding val before recursing left and right children of tree in Node case doesn't work.
data Tree = Leaf Int | Node Tree Tree Int
mkTree :: Int -> Tree
mkTree depth = if depth <= 0 then
Leaf depth
else
let left = mkTree (depth - 1)
right = mkTree (depth - 1)
in Node left right depth
sumTree :: Tree -> Int
sumTree tree = case tree of
Leaf val -> val
Node left right val -> val + sumTree(left) + sumTree(right)
gibbon_main = sumTree (mkTree 10)
Get the following error:
gibbon: Var val_18_94_155 not found. Checking:
: VarE "val_18_94_155"
CallStack (from HasCallStack):
error, called at src/Gibbon/L3/Typecheck.hs:824:21 in gibbon-0.2-inplace:Gibbon.L3.Typecheck
However demanding the value in order works, following code works:
data Tree = Leaf Int | Node Tree Tree Int
mkTree :: Int -> Tree
mkTree depth = if depth <= 0 then
Leaf depth
else
let left = mkTree (depth - 1)
right = mkTree (depth - 1)
in Node left right depth
sumTree :: Tree -> Int
sumTree tree = case tree of
Leaf val -> val
Node left right val -> sumTree(left) + sumTree(right) + val
gibbon_main = sumTree (mkTree 10)
The text was updated successfully, but these errors were encountered:
Given the post order program, demanding val before recursing left and right children of tree in Node case doesn't work.
Get the following error:
However demanding the value in order works, following code works:
The text was updated successfully, but these errors were encountered: