Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created March 9, 2018 01:21
Show Gist options
  • Save KirinDave/b549238e612e7ffa33b35ba43b1ee380 to your computer and use it in GitHub Desktop.
Save KirinDave/b549238e612e7ffa33b35ba43b1ee380 to your computer and use it in GitHub Desktop.
createAndSumTree :: [Int] -> Int
createAndSumTree lst = hylo sum build lst where
sum (LeafF v) = v
sum (NodeF v0 v1) = v0 + v1
build [val] = LeafF val
build lst = NodeF l r
where (l, r) = splitAt (length lst `div` 2) lst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment