From 673dd2853791245254a0a7db9ac77fedd1735906 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 6 Dec 2017 09:47:40 -0700 Subject: [PATCH] Pick IDs for nodes. --- src/Rendering/DOT.hs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Rendering/DOT.hs b/src/Rendering/DOT.hs index 6fe3ebb20..592fff2fd 100644 --- a/src/Rendering/DOT.hs +++ b/src/Rendering/DOT.hs @@ -18,16 +18,15 @@ renderDOTDiff :: Both Blob -> Diff syntax ann1 ann2 -> B.ByteString renderDOTDiff _ _ = "" renderDOTTerm :: (ConstructorName syntax, Foldable syntax, Functor syntax) => Blob -> Term syntax ann -> B.ByteString -renderDOTTerm Blob{..} term = renderGraph (snd (cata graphAlgebra term)) { graphName = Just (B.pack blobPath) } +renderDOTTerm Blob{..} term = renderGraph (snd (cata graphAlgebra term 0)) { graphName = Just (B.pack blobPath) } -graphAlgebra :: (ConstructorName syntax, Foldable syntax) => TermF syntax ann (Int, Graph) -> (Int, Graph) -graphAlgebra t = (i, Graph +graphAlgebra :: (ConstructorName syntax, Foldable syntax) => TermF syntax ann (Int -> (Int, Graph)) -> Int -> (Int, Graph) +graphAlgebra t i = (succ i, Graph Nothing - (Node i (unConstructorLabel (constructorLabel t)) : (g >>= graphNodes . snd)) - (map (Edge i . fst) g <> (g >>= graphEdges . snd))) - where g = toList t - i = 0 + (Node (succ i) (unConstructorLabel (constructorLabel t)) : (g >>= graphNodes . snd)) + (map (Edge (succ i) . fst) g <> (g >>= graphEdges . snd))) + where g = map ($ succ i) (toList t) renderGraph :: Graph -> B.ByteString