<div dir="ltr">On Thu, Sep 8, 2011 at 01:56, Zhi-Qiang Lei <span dir="ltr"><<a href="mailto:zhiqiang.lei@gmail.com">zhiqiang.lei@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
When ('f' : "oo") ++ "bar" becomes 'f' : ("oo" ++ "bar") and then becomes 'f' : ('o' : ("o" ++ "bar")), we still need 'f', don't we?</blockquote>
</div><br>Haskell lists are singly-linked lists, not arrays or double-linked lists or etc. Once we've evaluated past a given ":", there is no way to go back to what precedes it; it's no longer reachable (unless the caller, who has been passed the earlier part, is holding onto it) and the garbage collector will reclaim it.<div>
<br></div><div>Put slightly differently: as you've phrased it, evaluation would expand each element but always start stepping into it from the very start. That's not what happens; as the evaluator steps through the list, it throws away its reference to the earlier part completely. So it never becomes 'f' : ('o' : ("o" ++ "bar"))) because when the evaluator is at the 'o' it has completely forgotten about the 'f'. It's got 'o' : ("o" ++ "bar") and any remaining reference (if there is one) to the 'f' is held by something else.<br>
<div><br></div><div><div>-- <br>brandon s allbery <a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a><br>wandering unix systems administrator (available) (412) 475-9364 vm/sms<br>
<br>
</div></div></div></div>