<div dir="ltr">I'm sorry, my example should've been:<br><br>[1,2,3] >>= \a -> [a+1] >>= \a -> return a<br></div><br><div class="gmail_quote">On Tue, Apr 28, 2015 at 1:12 PM Grzegorz Milka <<a href="mailto:grzegorzmilka@gmail.com">grzegorzmilka@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Hi,<br>
<br>
The variable is not reassigned, but hidden. The do notation is a
syntactic sugar for:<br>
<br>
<blockquote>[1, 2, 3] >>= (\a -> <br>
[a + 1] >>= (\a -><br>
return a))<br>
</blockquote>
<br>
The second 'a' is inside a nested lambda function and therefore
inside a nested scope. The first 'a' still exists, but the value to
which it refers is hidden inside the second lambda function, where
'a' is bound to a different value. <br></div><div bgcolor="#FFFFFF" text="#000000">
<br>
<div>On 28.04.2015 11:53, Shishir Srivastava
wrote:<br>
</div>
<blockquote type="cite">
<pre>Hi,
Please can anyone explain how does 'a' get re-used in the code below. My
understanding so far of haskell is that variables are not allowed to mutate
or re-assigned.
---
do
a <- [1,2,3]
a <- [a+1]
return a
[2,3,4]
---
Thanks,
Shishir
</pre>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
Beginners mailing list
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</pre>
</blockquote>
<br>
</div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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>
</blockquote></div>