title: Haskell binary tree fast implementation
body: <p>I implemented binary tree data structure in Haskell.</p>
  
  <p>My code:</p>
  
  <pre><code>module Data.BTree where
  
  data Tree a = EmptyTree 
                  | Node a (Tree a) (Tree a)
                  deriving (Eq, Ord, Read, Show)
  
  emptyTree :: a -&gt; Tree a  
  emptyTree a = Node a EmptyTree EmptyTree
  
  treeInsert :: (Ord a) =&gt; a -&gt; Tree a -&gt; Tree a
  treeInsert x EmptyTree = emptyTree 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))
  
  
  fillTree :: Int -&gt; Tree Int -&gt; Tree Int
  fillTree  10000 tree = tree 
  fillTree  x tree = let a = treeInsert x tree
                     in fillTree (x + 1) a
  </code></pre>
  
  <p>This code very slow. I run:</p>
  
  <pre><code>fillTree 1 EmptyTree
  </code></pre>
  
  <p>I get : 50.24 secs</p>
  
  <p>I try to implement this code in C language and my result of this test: 0m0.438s</p>
  
  <p>Why so big difference? Is Haskell code rely so slow or my binary tree in haskell bad? I want to ask haskell guru maybe i can make my binary tree implementation more effective?</p>
  
  <p>Thank you.</p>