Hi Rohit,<br>You can probably ignore the first line of my reply, if it feels a bit confusing :)<br><br><div class="gmail_quote">On Sun, Sep 5, 2010 at 3:16 PM, <a href="mailto:lakshminaras2002@gmail.com">lakshminaras2002@gmail.com</a> <span dir="ltr">&lt;<a href="mailto:lakshminaras2002@gmail.com">lakshminaras2002@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">The idea behind pattern matching is that you can use any of the data constructor for the type to dismantle the value coming in.<br>

<br>
For depthTree, the type of value expected is Tree a. The Node 
constructor is used to dismantle the incoming value into three parts and
 bind it to variables x u v. Note here that depthTree accepts only one 
argument as input and the type of that value is (Tree a)<br>
<br>
When you do not want to dismantle the incoming value, then you would not
 use any data constructor. Your function would then become, <br>
    depthTree :: Tree a -&gt; Int<br>
    depthTree x = ..<br>
<br>
You cannot use depthTree (x u v) because the compiler would then try to 
look for a data constructor x . And in Haskell, data constructor names 
begin with a uppercase letter.<br>
<br>
You can refer to this page on Haskell wiki book<a href="http://en.wikibooks.org/wiki/Haskell/Pattern_matching" target="_blank"> http://en.wikibooks.org/wiki/Haskell/Pattern_matching </a>for more information.<div><div></div>
<div class="h5"><br><br><div class="gmail_quote">
On Sun, Sep 5, 2010 at 2:18 PM, Rohit Garg <span dir="ltr">&lt;<a href="mailto:rpg.314@gmail.com" target="_blank">rpg.314@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

Hi,<br>
<br>
I am working on exercises in RWH, chapter 3 and I have a a question<br>
about the pattern matching in the depth-of-tree question.<br>
<br>
The tree datatype is defined as<br>
<br>
data Tree a = Node a (Tree a) (Tree a)<br>
            | Empty<br>
              deriving (Show)<br>
<br>
And to pattern match on it, I need to write<br>
<br>
depthTree (Node x u v) = 1 + max (depthTree u) (depthTree v)<br>
<br>
My question is why do I need to prefix x with Node? Why can&#39;t it<br>
pattern match on depthTree (x u v)? More generally, where do I need to<br>
put data constructors in pattern matches?<br>
<font color="#888888"><br>
--<br>
Rohit Garg<br>
<br>
<a href="http://rpg-314.blogspot.com/" target="_blank">http://rpg-314.blogspot.com/</a><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</font></blockquote></div><br><br clear="all"><br></div></div><font color="#888888">-- <br>Regards<br>Lakshmi Narasimhan T V<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Regards<br>Lakshmi Narasimhan T V<br>