fork download
  1. module Main (main) where
  2.  
  3. data BinTree a = Empty | Node a (BinTree a) (BinTree a)
  4. deriving (Show)
  5.  
  6. showTree :: Show a => BinTree a -> Int -> String
  7. showTree (Empty) _ = []
  8. showTree (Node t l r) n = replicate n '*' ++ show t ++ "\n" ++ showTree l (n+1) ++ showTree r (n+1)
  9.  
  10. main :: IO ()
  11. main = do
  12. let x = Node "Parent" (Node "childLeft" (Node "grandChildLeftLeft" Empty Empty) Empty) (Node "childRight" Empty Empty)
  13. putStrLn $ showTree x 0
Success #stdin #stdout 0s 6228KB
stdin
Standard input is empty
stdout
"Parent"
*"childLeft"
**"grandChildLeftLeft"
*"childRight"