Yes, &nbsp;Just must be executed because by the very definition of bind for the Maybe mondad,<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(&gt;&gt;=) Nothing f = Nothing<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(&gt;&gt;=) (Just x) f = f x<br><br>He need to know if the value injected is Just or &nbsp; Nothing, but anyway, my point is : it is just plain lazy functional code!. No magic inside. everything depend on the definition of bind.<br>
<br><br>2009/2/11 wren ng thornton &lt;<a href="mailto:wren@freegeek.org">wren@freegeek.org</a>&gt;<br>&gt;<br>&gt; Alberto G. Corona wrote:<br>&gt;&gt;<br>&gt;&gt; forwarded:<br>&gt;&gt;<br>&gt;&gt; Yes! &nbsp;if no state is passed, the optimization makes sense and the term is<br>
&gt;&gt; not executed, like any lazy evaluation. For example, I used the debugger<br>&gt;&gt; (that is, without optimizations) to verify it with the Maybe monad:<br>&gt;&gt; op x= x+x<br>&gt;&gt;<br>&gt;&gt; print $ Just (op 1) &gt;&gt;= \y-&gt; return (Just 2)<br>
&gt;&gt;<br>&gt;&gt; does not evaluate &nbsp;op 1<br>&gt;<br>&gt; Presumably you mean?: print $ Just (op 1) &gt;&gt;= \y-&gt; return 2<br>&gt;<br>&gt;<br>&gt;&gt; but<br>&gt;&gt;<br>&gt;&gt; print $ Just (op 1) &gt;&gt;= \y-&gt; return y<br>
&gt;&gt;<br>&gt;&gt; does execute it.<br>&gt;<br>&gt;<br>&gt; Dashing off towards the White Knight, we should be careful what is said here. If we take only the expression &quot;Just (op 1) &gt;&gt;= \y-&gt; return y&quot; then evaluating it yields &quot;Just (op 1)&quot;. That is, it only evaluates to WHNF and does not evaluate what&#39;s inside. It is only once this value is subsequently handed off to print or some other function, that it may become evaluated.<br>
&gt;<br>&gt; Similarly with the first example as originally written. It so happens that bind is non-strict for the field in Just, so we can discard the &quot;op 1&quot;. However, according to the semantics we do not evaluate &quot;Just 2&quot; either; we only need to evaluate the return which will produce Just and pass the operand down. (Regardless of the fact that the value yielded by applying Just to 2 is Just 2. Expressions and their denotations are different.)<br>
&gt;<br>&gt; --<br>&gt; Live well,<br>&gt; ~wren<br>&gt; _______________________________________________<br>&gt; Haskell-Cafe mailing list<br>&gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br><br>