partitionParenthesis parens = recurse 0 "" parens where
  recurse :: Int -> String -> String -> [String]
  recurse 1 s (')':remaining) = reverse (')':s) : partitionParenthesis remaining
  recurse n s ('(':remaining) = recurse (n+1) ('(':s) remaining
  recurse n s (')':remaining) = recurse (n-1) (')':s) remaining
  recurse n s "" = error $ show n
  -- recurse n ("(":remaining)) =

-- gretasFunction :: Forest -> Partition -> Integer
-- gretasFunction f (p:ps) = recurse ps (takeFromTree p f) where
  -- recurse [] forests
partitionParenthesis parens = recurse 0 "" parens where
  recurse :: Int -> String -> String -> [String]
  recurse 1 s (')':remaining) = reverse (')':s) : partitionParenthesis remaining
  recurse n s ('(':remaining) = recurse (n+1) ('(':s) remaining
  recurse n s (')':remaining) = recurse (n-1) (')':s) remaining
  recurse n s "" = error $ show n
  -- recurse n ("(":remaining)) =

-- gretasFunction :: Forest -> Partition -> Integer
-- gretasFunction f (p:ps) = recurse ps (takeFromTree p f) where
  -- recurse [] forests
partitionParenthesis parens = recurse 0 "" parens where
  recurse :: Int -> String -> String -> [String]
  recurse 1 s (')':remaining) = reverse (')':s) : partitionParenthesis remaining
  recurse n s ('(':remaining) = recurse (n+1) ('(':s) remaining
  recurse n s (')':remaining) = recurse (n-1) (')':s) remaining
  recurse n s "" = error $ show n
  -- recurse n ("(":remaining)) =

-- gretasFunction :: Forest -> Partition -> Integer
-- gretasFunction f (p:ps) = recurse ps (takeFromTree p f) where
  -- recurse [] forests