Skip to content

Commit

Permalink
more bench examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vidsinghal committed Jan 25, 2024
1 parent 25fa6ec commit 9918357
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module TreeSum where

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


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


copyPackedInt :: PackedInt -> PackedInt
copyPackedInt a = case a of
P b -> P b

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



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

data PackedInt = P Int
data Tree = Node PackedInt Tree Tree | 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

expo :: Int -> Int -> Int
{-# INLINE expo #-}
expo power val = if power == 0
then val
else val * expo (power-1) val


expo2 :: PackedInt -> PackedInt
expo2 val = case val of
P x -> P (expo 10 x)

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



gibbon_main = let
tree = mkTree 27
sum = iterate (expoTree tree)
in ()

0 comments on commit 9918357

Please sign in to comment.