-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9918357
commit 3da170f
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
gibbon-compiler/examples/layout_bench/ECOOP-2024-Bench/TreeAddOnePostPre.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module TreeAddOne where | ||
|
||
|
||
data PackedInt = P Int | ||
data Tree = Node Tree Tree PackedInt | Nil | ||
|
||
|
||
mkTree :: Int -> Tree | ||
mkTree depth = if depth <= 0 | ||
then Nil | ||
else | ||
let | ||
left = mkTree (depth-1) | ||
right = mkTree (depth-1) | ||
val = P depth | ||
in Node left right val | ||
|
||
addOne :: PackedInt -> PackedInt | ||
addOne val = case val of | ||
P b -> P (b+1) | ||
|
||
addOneTree :: Tree -> Tree | ||
addOneTree tree = case tree of | ||
Node l r val -> let | ||
a1 = addOne val | ||
sl = addOneTree l | ||
sr = addOneTree r | ||
in Node sl sr a1 | ||
Nil -> Nil | ||
|
||
|
||
|
||
gibbon_main = let | ||
tree = mkTree 27 | ||
newTree = iterate (addOneTree tree) | ||
in () |
36 changes: 36 additions & 0 deletions
36
gibbon-compiler/examples/layout_bench/ECOOP-2024-Bench/TreeCopyPostPre.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
newVal = copyPackedInt val | ||
sl = copyTree l | ||
sr = copyTree r | ||
in Node newVal sl sr | ||
Leaf -> Leaf | ||
|
||
|
||
|
||
gibbon_main = let | ||
tree = mkTree 27 | ||
newTree = iterate (copyTree tree) | ||
in () --printPacked newTree |
42 changes: 42 additions & 0 deletions
42
gibbon-compiler/examples/layout_bench/ECOOP-2024-Bench/TreeExpoPostPre.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
a1 = expo2 val | ||
sl = expoTree l | ||
sr = expoTree r | ||
in Node a1 sl sr | ||
Nil -> Nil | ||
|
||
|
||
|
||
gibbon_main = let | ||
tree = mkTree 27 | ||
sum = iterate (expoTree tree) | ||
in () |