Skip to content

Instantly share code, notes, and snippets.

@tarquin-the-brave
Created May 12, 2020 12:44
Show Gist options
  • Save tarquin-the-brave/3cae6f3afd87303b9de598db29293743 to your computer and use it in GitHub Desktop.
Save tarquin-the-brave/3cae6f3afd87303b9de598db29293743 to your computer and use it in GitHub Desktop.
levels :: Tree a -> [[a]]
sumDepthsTree :: Integral b => Tree a -> b
sumDepthsTree = snd . foldl foldFunc (0, 0) . levels
foldFunc :: Integral a => (a,a) -> [b] -> (a,a)
foldFunc (depth, acc) x = (depth + 1, acc + depth * genericLength x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment