title: Reading a tree from file in Haskell
body: <p>I want to create a tree from a file in Haskell. For that, i read the file into this list of lists:</p>
  
  <p>The names in each element of the list follow this pattern:</p>
  
  <pre><code>["Name","Dad","Mum"]
  
  [["Bob","Dylan","Susan"],
   ["Dylan","Cole","Sarah"],
   ["Cole","Patrick","Patricia"],
   ["Sarah","David","Fiona"],
   ["Susan","Michael","Madeline"]]
  </code></pre>
  
  <p>The desired output is something like:</p>
  
  <pre><code>Bob
        Dylan
              Cole
                    Patrick
                    Patricia
              Sarah
                    David
                    Fiona
        Susan
              Michael
              Madeline
  </code></pre>
  
  <p>The spaces could be a tab, i just put more to emphasise my point.</p>
  
  <p>Here's what i've managed to do so far:</p>
  
  <pre><code>data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show, Read, Eq) 
  
  singleton :: a -&gt; Tree a  
  singleton x = Node x EmptyTree EmptyTree  
  
  treeInsert :: (Ord a) =&gt; a -&gt; Tree a -&gt; Tree a  
  treeInsert x EmptyTree = singleton x  
  treeInsert x (Node a left right)   
      | x == a = Node x left right  
      | x &lt; a  = Node a (treeInsert x left) right  
      | x &gt; a  = Node a left (treeInsert x right)  
  
  createTree :: (Ord a) =&gt; [a] -&gt; Tree a
  createTree [] = EmptyTree
  createTree (x:xs) = createTree2 (Node x EmptyTree EmptyTree) xs
    where
      createTree2 tree [] = tree
      createTree2 tree (y:ys) = createTree2 (treeInsert y tree) ys
  
  printTree :: Show a =&gt; Tree a -&gt; IO ()
  printTree = (mapM_ putStrLn) . treeIndent
    where
      treeIndent EmptyTree          = ["\nEmpty Tree\n"]
      treeIndent (Node v lb rb) =
        [(show v)] ++
        map ("      " ++) ls ++
        ("" ++ r) : map ("   " ++) rs
      where
          (r:rs) = treeIndent $ rb
          ls     = treeIndent $ lb
  </code></pre>
  
  <p>All this lets me, very basically create the tree, and print it to the screen. What i'm struggling with is the proper creating of the tree according to this problem.</p>