Série: haskell
haskell
34 linhas
· Atualizado 2026-02-03
DrawTree.hs
haskell/Week9/DrawTree.hs
module DrawTree(
BinaryTree(Null, Node),
printTree -- :: (Show a) => BinaryTree a -> IO ()
) where
{-
Module for drawing nice looking trees
David Quarel 13/02/2019
Don't worry too much about how this works,
or the types of these functions.
It's beyond the scope of this course.
Code modified from
http://hackage.haskell.org/package/containers-0.5.7.1/docs/src/Data.Tree.html#drawTree
-}
data BinaryTree a = Null | Node (BinaryTree a) a (BinaryTree a)
deriving Show
printTree :: (Show a) => BinaryTree a -> IO ()
printTree = putStr.unlines.draw
draw :: (Show a) => BinaryTree a -> [String]
draw Null = ["Null"]
draw (Node left x right) = (show x) : drawSubTrees [right,left]
where
drawSubTrees [] = []
drawSubTrees [t] =
"|" : shift "`- " " " (draw t)
drawSubTrees (t:ts) =
"|" : shift "+- " "| " (draw t) ++ drawSubTrees ts
shift first other = zipWith (++) (first : repeat other)
Artigos relacionados
haskell
haskell
Atualizado 2026-02-03
Adding.hs
Adding.hs — haskell source code from the haskell learning materials (haskell/Adding.hs).
Ler artigo →
haskell
haskell
Atualizado 2026-02-03
Area.hs
Area.hs — haskell source code from the haskell learning materials (haskell/Area.hs).
Ler artigo →
haskell
haskell
Atualizado 2026-02-03
Chess.hs
Chess.hs — haskell source code from the haskell learning materials (haskell/Chess.hs).
Ler artigo →
haskell
haskell
Atualizado 2026-02-03
ChessGraphics.hs
ChessGraphics.hs — haskell source code from the haskell learning materials (haskell/ChessGraphics.hs).
Ler artigo →
haskell
haskell
Atualizado 2026-02-03
Examples.hs
Examples.hs — haskell source code from the haskell learning materials (haskell/Examples.hs).
Ler artigo →
haskell
haskell
Atualizado 2026-02-03
Fibonacci.hs
Fibonacci.hs — haskell source code from the haskell learning materials (haskell/Fibonacci.hs).
Ler artigo →