Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
vidsinghal committed Jan 26, 2024
1 parent 3da170f commit a82d9bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module TreeSum where

data PackedInt = P Int
data Tree = Node PackedInt Tree Tree | Leaf
data Tree = Node Tree Tree PackedInt | Leaf


mkTree :: Int -> Tree
mkTree depth = if depth <= 0
then Leaf
else
let
val = P depth
let
left = mkTree (depth-1)
right = mkTree (depth-1)
in Node val left right
val = P depth
in Node left right val


copyPackedInt :: PackedInt -> PackedInt
Expand All @@ -21,16 +21,16 @@ copyPackedInt a = case a of

copyTree :: Tree -> Tree
copyTree tree = case tree of
Node val l r -> let
Node l r val -> let
newVal = copyPackedInt val
sl = copyTree l
sr = copyTree r
in Node newVal sl sr
in Node sl sr newVal
Leaf -> Leaf



gibbon_main = let
tree = mkTree 27
newTree = iterate (copyTree tree)
in () --printPacked newTree
in ()
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module TreeExpo where

data PackedInt = P Int
data Tree = Node PackedInt Tree Tree | Nil
data Tree = Node Tree Tree PackedInt | Nil


mkTree :: Int -> Tree
mkTree depth = if depth <= 0
then Nil
else
let
val = P depth
left = mkTree (depth-1)
right = mkTree (depth-1)
in Node val left right
val = P depth
in Node left right val

expo :: Int -> Int -> Int
{-# INLINE expo #-}
Expand All @@ -27,11 +27,11 @@ expo2 val = case val of

expoTree :: Tree -> Tree
expoTree tree = case tree of
Node val l r -> let
Node l r val -> let
a1 = expo2 val
sl = expoTree l
sr = expoTree r
in Node a1 sl sr
in Node sl sr a1
Nil -> Nil


Expand Down

0 comments on commit a82d9bb

Please sign in to comment.