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

PostOrder Traversal for Tree doesn't compile in Gibbon for the case where scalar is demanded out of order. #196

Open
vidsinghal opened this issue Feb 24, 2023 · 0 comments
Assignees

Comments

@vidsinghal
Copy link
Collaborator

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)
@ckoparkar ckoparkar removed their assignment Feb 25, 2023
@vidsinghal vidsinghal self-assigned this Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants