title: Haskell : Comparing if two binary trees have the same elements
body: <p>So I am working on a function that detects if two binary trees have the same numbers in them.</p>
  
  <p>So what I've come up with is the following which works just fine but the problem is that I am using total of 5 functions. Is there another way of detecting if two BT's have the same elements with just one function ? Here is my solution so far which seems to work just fine.</p>
  
  <pre><code>flatten :: BinTree a -&gt; [a]
  flatten Empty        = []
  flatten (Node l x r) = flatten l ++ [x] ++ flatten r
  
  splt :: Int -&gt; [a] -&gt; ([a], [a])
  splt 0 xs = ([], xs)
  splt _ [] = ([],[])
  splt n (x:xs) = (\ys-&gt; (x:fst ys, snd ys)) (splt (n-1) xs)
  
  merge :: Ord a =&gt; [a] -&gt; [a] -&gt; [a] 
  merge xs [] = xs
  merge [] ys = ys    
  merge (x:xs) (y:ys) = if (x &gt; y) then y:merge (x:xs) ys else x:merge xs(y:ys)
  
  msort :: Ord a =&gt; [a] -&gt; [a]
  msort [] =[]
  msort (x:[]) = (x:[])
  msort xs = (\y -&gt; merge (msort (fst y)) (msort (snd y))) (splt (length xs `div` 2) xs)
  
  areTreesEqual :: (Ord a) =&gt; BinTree a -&gt; BinTree a-&gt; Bool
  areTreesEqual Empty Empty = True
  areTreesEqual Empty a = False
  areTreesEqual a Empty = False
  areTreesEqual a b = msort (flatten (a) ) == msort (flatten (b))
  </code></pre>