summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2012-06-14 09:26:51 +1000
committerJed Barber <jjbarber@y7mail.com>2012-06-14 09:26:51 +1000
commit533dcc1b4ab16bf167a8f9b08000be30cd0a39c2 (patch)
treed91db42f9f4899238abb3d68ecd747a25e5a5b07
parentaac71dbd542266399999676f5380673e472219a5 (diff)
Added Show instance for the graph
-rw-r--r--ProofGraph.hs16
1 files 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