Advertisement
ulysses4ever

sumtree in Parallel Gibbon

Jul 9th, 2024 (edited)
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Main where
  2.  
  3. data Tree = Leaf Int
  4.           | Node Int Tree Tree
  5.  
  6. mkTree :: Int -> Tree
  7. mkTree i =
  8.   if i <= 0
  9.   then Leaf 1
  10.   else
  11.       let x = (mkTree (i-1))
  12.           y = (mkTree (i-1))
  13.       in Node i x y
  14.  
  15. sumTree :: Tree -> Int
  16. sumTree foo =
  17.   case foo of
  18.     Leaf i     -> i
  19.     Node i a b ->
  20.       let tup = par (sumTree a) (sumTree b)
  21.           x = fst tup
  22.           y = snd tup
  23.       in x + y
  24.  
  25. gibbon_main = sumTree (mkTree 27)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement