<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body 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>
<br>
<div class="moz-cite-prefix">On 28.04.2015 11:53, Shishir Srivastava
wrote:<br>
</div>
<blockquote
cite="mid:CALe5RTvSTZQd0nGWtrMKXrdDrykAPOzUEaXjWupy888ruvnnsw@mail.gmail.com"
type="cite">
<pre wrap="">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 class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</pre>
</blockquote>
<br>
</body>
</html>