From 533dcc1b4ab16bf167a8f9b08000be30cd0a39c2 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 14 Jun 2012 09:26:51 +1000 Subject: Added Show instance for the graph --- ProofGraph.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ProofGraph.hs b/ProofGraph.hs index 0cd2e7e..6459591 100644 --- a/ProofGraph.hs +++ b/ProofGraph.hs @@ -10,16 +10,28 @@ module ProofGraph ( import Data.Set( Set ) import qualified Data.Set as Set +import qualified Data.List as List data Node a = Node { contents :: a - , successors :: Set (Node a) } deriving (Eq, Ord, Show) + , successors :: Set (Node a) } deriving (Eq, Ord) -data Graph a = Graph { nodes :: Set (Node a) } deriving (Show) +data Graph a = Graph { nodes :: Set (Node a) } +instance (Show a, Eq a) => Show (Node a) where + show x = let header = "ID: " ++ (show . contents $ x) + footer = if ((successors x) == Set.empty) + then "\n" + else " -> " ++ List.intercalate ", " (map (show . contents) (Set.toList . successors $ x)) ++ "\n" + in header ++ footer + +instance (Show a, Eq a) => Show (Graph a) where + show x = "Graph: \n" ++ List.foldl' (++) [] (map show (Set.toList . nodes $ x)) ++ "\n" + + empty :: Graph a empty = Graph Set.empty -- cgit