[project @ 2003-08-11 18:39:56 by ross]
authorross <unknown>
Mon, 11 Aug 2003 18:39:56 +0000 (18:39 +0000)
committerross <unknown>
Mon, 11 Aug 2003 18:39:56 +0000 (18:39 +0000)
rename the cute presentations and use derived instances of Read and
Show, as suggested by Tomasz Zielonka.

Data/Tree.hs

index ac046d9..8524935 100644 (file)
 --
 -- Multi-way trees (/aka/ rose trees) and forests.
 --
--- Also included are neat presentations for trees and forests.
---
 -----------------------------------------------------------------------------
 
 module Data.Tree(
        Tree(..), Forest,
+       drawTree, drawForest,
        flatten, levels,
     ) where
 
 -- | Multi-way trees, also known as /rose trees/.
 data Tree a   = Node a (Forest a) -- ^ a value and zero or more child trees.
+#ifndef __HADDOCK__
+  deriving (Eq, Read, Show)
+#else /* __HADDOCK__ (which can't figure these out by itself) */
+instance Eq a => Eq (Tree a)
+instance Read a => Read (Tree a)
+instance Show a => Show (Tree a)
+#endif
 type Forest a = [Tree a]
 
 instance Functor Tree where
@@ -29,22 +35,13 @@ instance Functor Tree where
 mapTree              :: (a -> b) -> (Tree a -> Tree b)
 mapTree f (Node x ts) = Node (f x) (map (mapTree f) ts)
 
--- explicit instance for Haddock's benefit
-instance Eq a => Eq (Tree a) where
-  Node x ts == Node x' ts'  =  x == x' && ts == ts'
-
-instance Show a => Show (Tree a) where
-  show = showTree
-  showList ts s = showForest ts ++ s
-
-showTree :: Show a => Tree a -> String
-showTree  = drawTree . mapTree show
-
-showForest :: Show a => Forest a -> String
-showForest  = unlines . map showTree
+-- | Neat 2-dimensional drawing of a tree.
+drawTree :: Show a => Tree a -> String
+drawTree  = unlines . draw . mapTree show
 
-drawTree :: Tree String -> String
-drawTree  = unlines . draw
+-- | Neat 2-dimensional drawing of a forest.
+drawForest :: Show a => Forest a -> String
+drawForest  = unlines . map drawTree
 
 draw :: Tree String -> [String]
 draw (Node x ts0) = grp this (space (length this)) (stLoop ts0)