<div dir="ltr">Thanks Mike. The statement "<span style="font-size:12.8000001907349px"> A constructor is parsed as the name of the constructor being defined followed by zero or more types</span>" made everything clear. </div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 15, 2015 at 3:57 PM, Mike Meyer <span dir="ltr"><<a href="mailto:mwm@mired.org" target="_blank">mwm@mired.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">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></span><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>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Nishant</div>
</div>