title: Haskell: Mirroring a Binary Tree error: "Couldn't match expected type"
body: <p>So I am trying to design a function to return a binary tree that is a mirror of the originally sent binary tree. I think I have it almost done but I am getting  a weird "Couldn't match expected type. Here is my code:</p>
  
  <pre><code>mirror :: BinTree a -&gt; BinTree a    
  mirror (Node x tL tR) = Node x (mirror tR) (mirror tL)
  </code></pre>
  
  <p><strong>And here is the error:</strong></p>
  
  <pre><code>hw1.hs:84:30:
      Couldn't match expected type `a' with actual type `BinTree a'
        `a' is a rigid type variable bound by
            the type signature for mirror :: BinTree a -&gt; BinTree a
            at hw1.hs:83:11
      In the first argument of `Node', namely `x'
      In the expression: Node x (mirror tR) (mirror tL)
      In an equation for `mirror':
          mirror (Node tL x tR) = Node x (mirror tR) (mirror tL)
  
  hw1.hs:84:33:
      Couldn't match expected type `a' with actual type `BinTree a'
        `a' is a rigid type variable bound by
            the type signature for mirror :: BinTree a -&gt; BinTree a
            at hw1.hs:83:11
      In the return type of a call of `mirror'
      In the second argument of `Node', namely `(mirror tR)'
      In the expression: Node x (mirror tR) (mirror tL)
  Failed, modules loaded: none.
  </code></pre>
  
  <p><strong>It was my fault. My definition of the tree was different.</strong></p>
  
  <pre><code>data BinTree a = Empty | Node (BinTree a) a (BinTree a) deriving (Eq,Show)
  </code></pre>
  
  <p>*<em>The new function is supposed to be : *</em></p>
  
  <pre><code>mirror :: BinTree a -&gt; BinTree a
  mirror Empty = Empty
  mirror (Node tL x tR) = Node (mirror tR) x (mirror tL)
  </code></pre>