-unfoldForestM_BF f = liftM (reverseOnto []) . unfoldForestQ f . listToQueue
- where reverseOnto :: [a'] -> Queue a' -> [a']
- reverseOnto as q = case deQueue q of
- Nothing -> as
- Just (a, q') -> reverseOnto (a:as) q'
-
--- takes a queue of seeds
--- produces a queue of trees of the same length, but in the reverse order
-unfoldForestQ :: Monad m => (b -> m (a, [b])) -> Queue b -> m (Queue (Tree a))
-unfoldForestQ f aQ = case deQueue aQ of
- Nothing -> return emptyQueue
- Just (a, aQ) -> do
+unfoldForestM_BF f = liftM toList . unfoldForestQ f . fromList
+
+-- takes a sequence (queue) of seeds
+-- produces a sequence (reversed queue) of trees of the same length
+unfoldForestQ :: Monad m => (b -> m (a, [b])) -> Seq b -> m (Seq (Tree a))
+unfoldForestQ f aQ = case viewl aQ of
+ EmptyL -> return empty
+ a :< aQ -> do