<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, May 15, 2015 at 4:48 AM, Nishant <span dir="ltr"><<a href="mailto:nishantgeek@gmail.com" target="_blank">nishantgeek@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>1 : data Tree a = NULL | Node a (Tree a) (Tree a)   works fine. But,<br></div><div>2  : data Tree a = NULL | Tree a (Node a) Tree a does not work. GHCI says Not in scope " type constructor or class 'Node'.   </div><div><br></div><div>Why is 2 declaration not valid though second definition looks much more closer to what a binary tree actually means ?  </div></div></blockquote><div><br></div><div>Because Haskell isn't english. A constructor is parsed as the name of the constructor being defined followed by zero or more types. Your first version defines the constructor name Node followed by the types a, Tree a and Tree a. The second one defines the constructor name Tree followed by the types a, Node a and Tree a. You have to define the type Node for this to work.</div><div><br></div><div>So you could do:</div><div><br></div><div>data Node a = Node a</div><div>data Tree a = NULL | Tree (Tree a) (Node a) (Tree a)</div><div><br></div><div>But then you have to say "Tree NULL (Node 1.0) NULL" to a tree holding 1.0 with empty left and right subtrees. If you do it they way you said first, you can just say "Node 1.0 Null Null".</div><div><br></div><div>Maybe you want "date Tree a = NULL | Node (Tree a) a (Tree a)"? Then you you can say "Node NULL 1.0 NULL". Or even "Date Tree a = NULL | Tree (Tree a) a (Tree a)", for "Tree NULL 1.0 NULL"?</div><div><br></div></div></div></div>