title: tree with defined Type in haskell
body: <p>I am trying to construct a tree from pre/postoreder traversals . My tree type is below:</p>
  
  <pre><code>        data Tree = Emptytree | Node Integer [Tree]
  </code></pre>
  
  <p>I am new in functional programming. So I come across with some difficulties while tying construct my base cases and recursion.My function will be something like this:</p>
  
  <pre><code>           ListToTree :: [Integer] -&gt; [Integer] -&gt; Tree
  </code></pre>
  
  <p>I construct some algorithms but I can not make it to fit to Language requirements. 
  My algorithm is quite simple:I take each element of first list (preorder traversal list) then I check it position in the  second list. Let me give an example:</p>
  
  <pre><code>                1                       
               /     \    
            2          5
           /  \
         3      4
  </code></pre>
  
  <p>Preorder of this Tree traversal is as you know [1,2,3,4,5]</p>
  
  <p>Postorder of this Tree traversal is as you know [3,4,2,5,1]</p>
  
  <p>Firstly I look to the first element of first list it is 1 then I look it is position it in 2nd list it is last so I add this to my tree. Then I check next element of tree it is 2 in the second list it on the left of 1 it means it is child of it. Then 3 is on the left of 2 (in the second list) it means it is also the son of 2 then i look to 4 it is on the left of 2 it is son of 2, and lastly 5 it is on the left of 1 it is child of one (because it is on the right of 2 it is not a child of 2).</p>
  
  <p>I tried to implement it . I write helper function which determines if Node has a child or not. I use also counter in my function So actually my function is like this:</p>
  
  <pre><code>           ListToTree :: Integer -&gt; [Integer] -&gt; [Integer] -&gt; Tree
             {-First Stands for counter ,2nd preorder, 3rd postorder-}
  </code></pre>
  
  <p>MY base condition are:</p>
  
  <pre><code>                 1. is about if list are Emptytree return Emptytree
                   2. is about if counter== length-1 return Node element [Emptytree]
  </code></pre>
  
  <p>My main problematic part is in my recursive part: </p>
  
  <pre><code>  ListToTree counter a b  
      | hasChild b counter == 1 = Node ( Element ) [ListToTree (1+counter) a b]
      | hasChild b counter == 0 = Node ( Element ) [Emptytree]
          {-My problematic part if node has no Child what I must change here-}
          {-Or what are your suggestions-}
  </code></pre>
  
  <p>I need help in improving my algorithm Any kind of help or comments will be highly appreciated.</p>