
5 Sep
2010
5 Sep
'10
8:48 a.m.
Hi, I am working on exercises in RWH, chapter 3 and I have a a question about the pattern matching in the depth-of-tree question. The tree datatype is defined as data Tree a = Node a (Tree a) (Tree a) | Empty deriving (Show) And to pattern match on it, I need to write depthTree (Node x u v) = 1 + max (depthTree u) (depthTree v) My question is why do I need to prefix x with Node? Why can't it pattern match on depthTree (x u v)? More generally, where do I need to put data constructors in pattern matches? -- Rohit Garg http://rpg-314.blogspot.com/