<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">The logical issue you're hitting is mostly because the REPL (ghci most likely) is simulating something that you should ignore for the moment (the IO monad).<div><br></div><div>In Haskell, typically, you don't define one thing, then define another thing "later". &nbsp;A definition in a Haskell program doesn't assign a value, it binds a value. &nbsp;While assignment says "a now has the value 5 + 3", binding says "a always has, now has, and always will have the value 5+3".</div><div><br></div><div>A Haskell program like this that binds the same value twice is simply incorrect:</div><div>a = 5+3</div><div>a = 5+4</div><div><br></div><div>There are two competing facts here.</div><div><br></div><div>When typing into the REPL, you can rebind values, because each subsequent line appears (at least in the logical model) in an inner definition to the past. &nbsp;This is how scoping comes into it – the later (and hence inner) let takes precedence because it is in a closer scope.</div><div><br></div><div>My advice to you would be to stop thinking of trying to re-assign values right now, it's not the correct way to think about a Haskell program at all.</div><div><br></div><div>Bob</div><div><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div><span class="Apple-style-span" style="font-family: Arial; "><pre>if (*ra4 != 0xffc78948) { return false; }</pre></span></div></span>
</div>
<br><div><div>On 22 Mar 2012, at 15:54, Jan Erik Moström wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On 2012-03-22 at 16:12 , Felipe Almeida Lessa wrote:<br><blockquote type="cite">Your conclusion is correct, but your reasoning is not. It's not due<br></blockquote><blockquote type="cite">to lazyness that x is recursively defined, it's because of the scope.<br></blockquote><blockquote type="cite">When you type your second x on the second line, that x will refer to<br></blockquote><blockquote type="cite">the closest (in scope) definition of something called x -- which is<br></blockquote><blockquote type="cite">the the definition of x on the second line itself.<br></blockquote><br>Aha, thanks for explaining. I didn't consider scope - I did some searching of scoping and need to think about that for a while, a bit different than 'normal'. However, I would like to ask one more thing:<br><br>Assume<br><br>let a = 5 + 3<br><br>Would 5+3 be calculated directly or would it be deferred to later?<br>Assume it's calculated and the value 8 is given the name 'a'. Then<br><br>let a = a + 4<br><br>What happens is that Haskell tries to evaluate the second 'a' on that line and then finds the first 'a' and enters into infinite recursion.<br><br>And this is what confuses me a little bit. I can type in 'let a = a + 4' and Haskell accepts it, the infinite recursion does not happen until I type 'a' to show the value, this makes me think that the evaluation is deferred to later (and also why I asked about 5+3). Is this correct?<br><br>- jem<br><br>_______________________________________________<br>Beginners mailing list<br><a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>http://www.haskell.org/mailman/listinfo/beginners<br></div></blockquote></div><br></div></body></html>