-1

I want to access the nodes, edges and properties of 'xDotGraph' (G.DotGraph) and set those again. Here is Haskell code that prints dot format graph using graphviz:

$ cat example.dot
 digraph {
     a [type1="", type2=""];
     b [type1="", type2=""];
     a -> b [label=""];
 }

import Data.GraphViz
import Data.Text.IO as T
import qualified Data.Text.Lazy as B
import qualified Data.Text.Lazy.IO as L
import qualified Data.GraphViz.Types.Generalised as G
import Data.GraphViz.Printing

xDotText <- L.readFile "example.xdot"
let xDotGraph = parseDotGraph xDotText :: G.DotGraph String
T.putStrLn $ renderDot $ toDot xDotGraph
David
  • 63
  • 1
  • 10
  • Please describe what you've tried so far and what hasn't worked for you. As it sits now, your question reads more like a "I don't want to do any work, do this for me." kind of question. – jkeuhlen Aug 08 '16 at 14:27
  • @jkeuhlen, I am looking for a function that takes this type of graph and returns nodes and edges. let ab = graphNodes xDotGraph let ab1 = graphEdges xDotGraph – David Aug 08 '16 at 14:35
  • Does [__graphNodes__](https://hackage.haskell.org/package/graphviz-2999.18.1.2/docs/Data-GraphViz-Types.html#v:graphNodes) work? – ErikR Aug 08 '16 at 14:39
  • @ErikR myProject5.hs:71:38: Expected a type, but ‘DotRepr [] (G.DotGraph String)’ has kind ‘GHC.Prim.Constraint’ In an expression type signature: DotRepr [] (G.DotGraph String) In the expression: graphNodes xDotGraph :: DotRepr [] (G.DotGraph String) In an equation for ‘ab’: ab = graphNodes xDotGraph :: DotRepr [] (G.DotGraph String) – David Aug 08 '16 at 14:50

1 Answers1

2

This works for me (mostly identical to your code but there are a few changes):

#!/usr/bin/env stack
{- stack runghc --resolver lts-6.0 --package graphviz
 -}
import Data.GraphViz
import Data.Text.IO as T
import qualified Data.Text.Lazy as B
import qualified Data.Text.Lazy.IO as L
import qualified Data.GraphViz.Types.Generalised as G
import Data.GraphViz.Printing
import Data.GraphViz.Types

main = do
  xDotText <- L.readFile "example.dot"
  let xDotGraph = parseDotGraph xDotText :: G.DotGraph String
  L.putStrLn $ renderDot $ toDot xDotGraph
  print $ graphNodes xDotGraph
  print $ graphEdges xDotGraph
ErikR
  • 51,541
  • 9
  • 73
  • 124