Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. wrap_print :: Show a => Rope a -> IO ()
  2. wrap_print rope = putStrLn "strict graph G {" >> printer 1 (Just rope) >> putStrLn "}"
  3.  
  4. printer :: Show a => Int -> Maybe ( Rope a ) -> IO ()
  5. printer index rope = case rope of (Just (Node weight left right)) -> putStr ( (show index) ++ "\n" ++ (show index) ++ " [label="++ "\"" ++ (show weight) ++ "\"" ++ "];" ++ "\n" ) >>
  6. putStr ((show index) ++ " -- " )>>
  7. printer (index*2 + 1) left >>
  8. putStr ((show index) ++ " -- " ) >>
  9. printer (index*2) right
  10. (Just (Leaf weight value)) -> putStr ((show index) ++ "\n" ++ (show index) ++ " [label=" ++ "\"" ++ (show value) ++ "\"" ++ ",shape=diamond, color = red];" ++ "\n")
  11. Nothing -> putStr ((show index) ++ "\n" ++ (show index) ++ " [label=" ++ "\"Nothing\"" ++ ",shape=diamond, color = red];" ++ "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement