summaryrefslogtreecommitdiff
path: root/ProofGraph.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ProofGraph.hs')
-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