title: Attempting to print a huffman code tree in haskell
body: <p>The function I made, <code>showTree</code>, takes a huffman tree with nodes and leaves and &quot;neatly&quot; prints it in the shell.</p>
  <p>Here is the function:</p>
  <pre><code>showTree :: Tree -&gt; String
  showTree (Leaf c i) = [c] ++ show i
  showTree (Node v t1 t2) =
      left ++ &quot;\n&quot; ++ middle ++ right
      where middle  = replicate (heightTree (Node v t1 t2)) ' ' ++ replicate (heightTree (Node v t1 t2)) ' ' ++ replicate (heightTree (Node v t1 t2)) ' ' ++ show v
            left    = showTree t1
            right   = showTree t2 
  </code></pre>
  <p>At the moment it prints the nodes and the leaves directly next to eachother. The output ends up looking like this:</p>
  <pre><code>i2
        4l2
              8a1
        2g1
           4h2
                    21r2
              5t1
           3n1
        2s1
                 13 4
        8e4
  </code></pre>
  <p>The first number you see in each element is the node number, followed by the leaf character and integer. I am attempting to make it look like this:</p>
  <pre><code>
          ' '(4)
                  8
      i(2)
          4
      l(2)
                      13
      a(1)
          2
      t(1)
                  5
  g(1)
      2
  s(1)
          3
      n(1)
                             21
                  e(4)
                      8
          h(2)
                  4
          r(2)
  </code></pre>
  <p>or something like that. I'm basically just struggling in trying to figure out how to only display the leaves at the end of the tree where they belong.</p>