---------------------------------------------------
-- * odds and ends
-- ----------------------------------------------------------------------

-- | Like 'flatten', but returns whole subtrees instead of
--   just nodes:
--
--   > a(b c(d e(f g)) h)
--   > b
--   > c(d e(f g))
--   > d
--   > e(f g)
--   > f
--   > g
--   > h
--
--  Invariant: @map rootLabel (subtrees x) == flatten x@
subtrees :: Tree a -> [Tree a]
subtrees t =
    grab t []
  where
    grab st@(Node _ ts) xs = st : foldr grab xs ts

mkLeaf :: a -> Tree 
subtrees :: Tree a -> [Tree a]
subtrees t =
    grab t []
  where
    grab st@(Node _ ts) xs = st : foldr grab xs ts
subtrees t =
    grab t []
  where
    grab st@(Node _ ts) xs = st : foldr grab xs ts