&gt; <span style="font-family:arial,sans-serif;font-size:13px">What value will result have in the following?</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">&gt; result &lt;- gcd&#39; 2 (3 `mod` 2)</span><br>

<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">First of all, your question suggests a mental model of assignables, which you want to avoid because it will just end up confusing you.</span></div>

<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Instead, you want to come to grips with true (lambda) variables. Read on!</span></div>

<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">The neat thing about FP in general is that you can keep DRY&#39;er than in other languages. Why? Because you can take any piece of code, circle almost anywhere, and the fragment you&#39;ve got is an honest-to-goodness expression that you can evaluate (modulo the free variables in that fragment). </span></div>

<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Define a name at the top-level and you&#39;re good to go replacing all lookalikes with that name. This is especially true in Haskell because of non-strict semantics, a.k.a. full beta-reduction.</span></div>

<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Ditto for an annulus, not just circle.</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br>

</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Back to your original question about the value of result. First of all the whole line isn&#39;t even an expression, being part of the sugaring over monadic syntax, which is likely the source of the confusion.</span></div>

<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">The bigger problem however, is that in general, abstracting over this particular example, result doesn&#39;t have the value you think it should have!</span><br>

</div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Take for instance:</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br>

</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">x :: Maybe Int</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">x = return Nothing</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br>

</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">That&#39;s (almost!) the desugar of</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><font face="arial, sans-serif">x = do</font></div>

<div><font face="arial, sans-serif">    result &lt;- return Nothing</font></div><div><font face="arial, sans-serif">    return result</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Now result has type Int, so let&#39;s ask: what&#39;s its Int-value?</font></div>

<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">See what I mean?</font></div><div><br></div><div>Ans: This &quot;result&quot; is actually a lambda variable, as is plain to see after desugaring. That&#39;s its value!</div>

<div><br></div><div class="gmail_extra"><br clear="all"><div>-- Kim-Ee</div>
<br><br><div class="gmail_quote">On Mon, Dec 24, 2012 at 6:47 PM,  <span dir="ltr">&lt;<a href="mailto:jugree@lavabit.com" target="_blank">jugree@lavabit.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hello.<br>
<br>
Could you explain this example(0)? Could you show its step by step<br>
execution?<br>
<br>
gcd&#39; :: Int -&gt; Int -&gt; Writer (DiffList String) Int<br>
gcd&#39; a b<br>
    | b == 0 = do<br>
        tell (toDiffList [&quot;Finished with &quot; ++ show a])<br>
        return a<br>
    | otherwise = do<br>
        result &lt;- gcd&#39; b (a `mod` b)<br>
        tell (toDiffList [show a ++ &quot; mod &quot; ++ show b ++ &quot; = &quot; ++ show (a<br>
`mod` b)])<br>
        return result<br>
<br>
Why does the above append the log to the beginning of the list?<br>
<br>
What value will result have in the following?<br>
<br>
result &lt;- gcd&#39; 2 (3 `mod` 2)<br>
<br>
(0) <a href="http://learnyouahaskell.com/for-a-few-monads-more#writer" target="_blank">http://learnyouahaskell.com/for-a-few-monads-more#writer</a><br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>