Hello,<div><br></div><div>Nobody has explained you why that doesn&#39;t compile...<div><br></div><div>Here&#39;s the deal</div><div><br></div><div>Suppose you have a data A which has a constructor named B and a Int</div><div>

<br></div><div>&gt; data A = B Int</div><div><br></div><div>now suppose you have a data C which has a constructor named A and a Int</div><div><br></div><div>&gt; data C = A Int</div><div><br></div><div>that compiles because the name of your data type is different from the constructor,</div>

<div><br></div><div>that is, the names of the data types and the constructors they have are in different</div><div>scopes, so for doing what you want, you would need to do:</div><div><br></div><div><span class="Apple-style-span" style="font-family: &#39;Droid Sans&#39;, arial, sans-serif; font-size: 13px; border-collapse: collapse; "><div style="color: rgb(32, 32, 32); ">

<font size="2"><font face="trebuchet ms,sans-serif"><div style="color: rgb(0, 51, 51); ">&gt; data A = Aconstructor Int</div></font></font></div><div style="color: rgb(32, 32, 32); "><font size="2"><font face="trebuchet ms,sans-serif"><div style="color: rgb(0, 51, 51); ">

&gt; data B = Bconstructor Int</div></font></font></div><div><font size="2"><font face="trebuchet ms,sans-serif"><div style="color: rgb(0, 51, 51); ">&gt; data AorB = A A  | B B</div><div style="color: rgb(0, 51, 51); ">
<br>
</div><div>Where the first A is a constructor named A and the second references a data type A,</div><div>idem for B</div><div><br></div><div>Hope that helps you,</div><div><br></div><div>Héctor Guilarte</div></font></font></div>

</span></div></div><div><div><br><div class="gmail_quote">On Tue, Dec 14, 2010 at 3:39 PM, Russ Abbott <span dir="ltr">&lt;<a href="mailto:russ.abbott@gmail.com">russ.abbott@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div dir="ltr"><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif">Is there a way to get this to work?</font></font></font><div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><br>



</font></font></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font size="2"><font face="trebuchet ms,sans-serif"><div style="color:rgb(0, 51, 51)">

data A = Aconstructor Int</div></font></font></div><div><font size="2"><font face="trebuchet ms,sans-serif"><div style="color:rgb(0, 51, 51)">data B = Bconstructor Int</div></font></font></div><div><font size="2"><font face="trebuchet ms,sans-serif"><div style="color:rgb(0, 51, 51)">



data AorB = A | B</div></font></font></div><div><font size="2"><font face="trebuchet ms,sans-serif"><div style="color:rgb(0, 51, 51)"><br></div></font></font></div><div><font size="2"><font face="trebuchet ms,sans-serif"><div>



<div><font color="#003333">f :: Int -&gt; AorB</font></div><div><font color="#003333"><div>f x </div><div>  | even x     = Aconstructor x </div><div>  | otherwise = Bconstructor x </div>

<div><br></div></font></div></div></font></font></div></blockquote><div><font size="2"><font face="trebuchet ms,sans-serif"><div style="color:rgb(0, 51, 51)"> I get this diagnostic.</div><div style="color:rgb(0, 51, 51)">



<br></div></font></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font size="2"><font face="trebuchet ms,sans-serif"><div><div><font color="#FF0000">Couldn&#39;t match expected type `AorB&#39; against inferred type `A&#39; </font></div>



</div></font></font></div></blockquote><div><font size="2"><font face="trebuchet ms,sans-serif"><div style="color:rgb(0, 51, 51)"><br></div><div style="color:rgb(0, 51, 51)">Since AorB is A or B, why is this not permitted?</div>



<div style="color:rgb(0, 51, 51)"><br></div><div style="color:rgb(0, 51, 51)">If instead I write </div><div style="color:rgb(0, 51, 51)"><br></div></font></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">



<div><font size="2"><font face="trebuchet ms,sans-serif"><div><font color="#003333">data AorB = Aconstructor Int | Bconstructor Int </font></div></font></font></div></blockquote><div><font size="2"><font face="trebuchet ms,sans-serif"><div>



<font color="#003333"><br></font></div><div><font color="#003333">everything works out ok. But what if I want separate types for A and B?</font></div><div><br></div><div style="color:rgb(0, 51, 51)">

Thanks,</div></font></font><div dir="ltr"><font><font face="&#39;trebuchet ms&#39;, sans-serif"><i><font color="#003333"><br><font color="#888888">-- Russ </font></font></i></font></font></div>
</div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">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>
<br></blockquote></div><br></div></div>