[project @ 2005-02-03 10:38:44 by simonmar]
[ghc-base.git] / Data / Tree.hs
index d04fe3d..5c95f2a 100644 (file)
@@ -20,9 +20,7 @@ module Data.Tree(
        flatten, levels,
        -- * Building trees
        unfoldTree, unfoldForest,
-#ifndef __NHC__
        unfoldTreeM, unfoldForestM,
-#endif
        unfoldTreeM_BF, unfoldForestM_BF,
     ) where
 
@@ -91,7 +89,6 @@ unfoldTree f b = let (a, bs) = f b in Node a (unfoldForest f bs)
 unfoldForest :: (b -> (a, [b])) -> [b] -> Forest a
 unfoldForest f = map (unfoldTree f)
 
-#ifndef __NHC__
 -- | Monadic tree builder, in depth-first order
 unfoldTreeM :: Monad m => (b -> m (a, [b])) -> b -> m (Tree a)
 unfoldTreeM f b = do
@@ -100,13 +97,14 @@ unfoldTreeM f b = do
        return (Node a ts)
 
 -- | Monadic forest builder, in depth-first order
+#ifndef __NHC__
 unfoldForestM :: Monad m => (b -> m (a, [b])) -> [b] -> m (Forest a)
-unfoldForestM f = mapM (unfoldTreeM f)
 #endif
+unfoldForestM f = mapM (unfoldTreeM f)
 
 -- | Monadic tree builder, in breadth-first order,
 -- using an algorithm adapted from
--- /Breadth­First Numbering: Lessons from a Small Exercise in Algorithm Design/,
+-- /Breadth-First Numbering: Lessons from a Small Exercise in Algorithm Design/,
 -- by Chris Okasaki, /ICFP'00/.
 unfoldTreeM_BF :: Monad m => (b -> m (a, [b])) -> b -> m (Tree a)
 unfoldTreeM_BF f b = liftM (fst . fromJust . deQueue) $
@@ -114,11 +112,11 @@ unfoldTreeM_BF f b = liftM (fst . fromJust . deQueue) $
 
 -- | Monadic forest builder, in breadth-first order,
 -- using an algorithm adapted from
--- /Breadth­First Numbering: Lessons from a Small Exercise in Algorithm Design/,
+-- /Breadth-First Numbering: Lessons from a Small Exercise in Algorithm Design/,
 -- by Chris Okasaki, /ICFP'00/.
 unfoldForestM_BF :: Monad m => (b -> m (a, [b])) -> [b] -> m (Forest a)
 unfoldForestM_BF f = liftM (reverseOnto []) . unfoldForestQ f . listToQueue
-  where reverseOnto :: [a] -> Queue a -> [a]
+  where reverseOnto :: [a'] -> Queue a' -> [a']
        reverseOnto as q = case deQueue q of
                Nothing -> as
                Just (a, q') -> reverseOnto (a:as) q'
@@ -133,7 +131,7 @@ unfoldForestQ f aQ = case deQueue aQ of
                tQ <- unfoldForestQ f (foldl addToQueue aQ as)
                let (ts, tQ') = splitOnto [] as tQ
                return (addToQueue tQ' (Node b ts))
-  where splitOnto :: [a] -> [b] -> Queue a -> ([a], Queue a)
+  where splitOnto :: [a'] -> [b'] -> Queue a' -> ([a'], Queue a')
        splitOnto as [] q = (as, q)
        splitOnto as (_:bs) q = case fromJust (deQueue q) of
                (a, q') -> splitOnto (a:as) bs q'