<div dir="ltr">If you consider the type of the operator <b>(:)</b> you have:<div><br></div><div>Prelude> :t (:)</div><div>(:) :: a -> [a] -> [a]</div><div><br></div><div>So it takes an element of type a and a list. So if you write 1:[2,3,4] the type is correct, because you give an integer 1 and a list of integers [2,3,4]. You will obtain the list of integers [1,2,3,4]. Similarly, writing 1:[] is correct and gives you [1] as result.</div><div><br></div><div>Then, if you write</div><div>0 : 1 : []</div><div>(as in your example), is the same as</div><div>0 : (1 : [])</div><div>so it means 0 : [1], which is [0,1]. So, the operator (:) is right associative.</div><div><br></div><div>If it was left associative, your example would give an error. Indeed</div><div>(0 : 1) : []</div><div>is not correct in Haskell.</div><div><br></div><div>Furthermore, your final examples are both false:</div><div><div><br></div><div>Prelude> [] == [] : []</div><div>False</div></div><div><div><br></div><div>[[], []] == [] : []</div><div>False</div></div><div><br></div><div>The following is True:</div><div><div>Prelude> [[]] == [] : []</div><div>True</div></div><div><br></div><div>Indeed if you write [] : [] youy mean you want to build a list whose first element (head) is [] and whose "tail" (i.e. the rest of the list) is the empty list.</div><div>So, if 1:[] is [1], then []:[] is [[]].</div><div><br></div><div>Ut</div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-08-18 11:13 GMT+02:00 trent shipley <span dir="ltr"><<a href="mailto:trent.shipley@gmail.com" target="_blank">trent.shipley@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Why does Haskell so often seem to treat [] as a general null.<div><br></div><div>For example I know 0 : 1 : [] gives [0, 1].</div><div><br></div><div>But shouldn't it produce a type fault in a consistent world?</div><div><br></div><div>Int:Int:List isn't properly a list.  It mixes types.</div><div><br></div><div>I expect something like:</div><div><br></div><div>Let GSN mean general_scalar_null.</div><div><br></div><div>1 : 2 : GSN  -- works</div><div><br></div><div>1 : 2 : []  -- type fault, cannot mix int and empty list in the same list.</div><div><br></div><div>And why does [] == [] : []</div><div>instead of [[], []] == [] : []</div><div><br></div><div>What sorts of nullity are there in core Haskell?</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Trent.</div><div><br></div></font></span></div>
<br>______________________________<wbr>_________________<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" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>