List rooted trees: Difference between revisions

→‎{{header|Haskell}}: (replaced foldTree with a simpler foldNest)
(→‎{{header|Haskell}}: (added implementation of foldTree for versions of Data.Tree that lack it))
(→‎{{header|Haskell}}: (replaced foldTree with a simpler foldNest))
Line 429:
(1 + foldr ((+) . rootLabel) 0 xs)
(sortBy (flip (comparing rootLabel)) xs)
--foldTree :: (a -> [b] -> b) -> Tree a -> b
--foldTree f = go where
-- go (Node x ts) = f x (map go ts)
 
commasFromTree :: Tree a -> String
commasFromTree = foldTreefoldNest (\_ xs -> '(' : (concat xs ++ ")"))
 
--foldTreefoldNest :: (a -> [b] -> b) -> Tree a -> b
foldNest f =
-- let go (Node x_ ts) = f x (map go ts)
in go
 
main :: IO ()
9,655

edits