<br><font size=2 face="sans-serif">Hello,</font>
<br>
<br><tt><font size=2>There is clearly a problem with the Haskell/monad
tutorials out there...</font></tt>
<br>
<br><tt><font size=2>&gt; The tutorials seriously need to step back and
start with <br>
&gt; something like, &quot;To enforce order of evaluation we evaluate <br>
&gt; closures* returning a defined type. &nbsp;The first closure will feed
<br>
&gt; its result to the second which will in turn feed it's result to <br>
&gt; the third. &nbsp;Since the third closure can't be evaluated without
<br>
&gt; having the results from the second and first (and thus they had <br>
&gt; to be evaluated earlier in time) we get a defined evaluation <br>
&gt; sequence. &nbsp;Here are some examples...&quot;<br>
&gt; </font></tt>
<br><tt><font size=2>The style of this description is nice; however the
description itself is wrong. </font></tt>
<br>
<br><tt><font size=2>Monads DO NOT determine order of evaluation. Previous
posts on this thread give several examples. </font></tt>
<br>
<br><tt><font size=2>In lazy languages, data dependencies determine the
order of evaluation. X must be evaluated before Y if Y depends upon the
result of X. You can force the order of evaluation without using a monad
just as you can have a monad which does not determine the order in which
things get evaluated.</font></tt>
<br>
<br><tt><font size=2>From the point of view of a programmer, a monad is
simply a useful (higher-order) combinator pattern. All monadic code can
be flattened by replacing occurrences of bind (&gt;&gt;=) with it's definition.</font></tt>
<br>
<br><tt><font size=2>One general intuition about monads is that they represent
computations rather than simple (already computed) values:</font></tt>
<br>
<br><tt><font size=2>&nbsp; &nbsp; x :: Int &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; -- x is an Int</font></tt>
<br>
<br><tt><font size=2>&nbsp; &nbsp; x :: Monad m =&gt; m Int &nbsp;-- x
is a computation of an Int</font></tt>
<br>
<br><tt><font size=2>&nbsp; &nbsp; x :: [Int] &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; -- x is a computation of an Int which can return multiplie
values</font></tt>
<br>
<br><tt><font size=2>&nbsp; &nbsp; x :: Maybe Int &nbsp; &nbsp; &nbsp;
&nbsp; -- x is a computation of an Int which might fail (return Nothing)</font></tt>
<br>
<br><tt><font size=2>&nbsp; &nbsp; x :: State s Int &nbsp; &nbsp; &nbsp;
-- x is a computation of an Int which relies on, and returns (possibly
modified) </font></tt>
<br><tt><font size=2>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- &nbsp; a value of type s. Note:
State s Int is isomorphic to: s -&gt; (Int,s)</font></tt>
<br>
<br><tt><font size=2>&nbsp; &nbsp; x :: IO Int &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;-- x is a computation of an Int which can interact with the
outside world.</font></tt>
<br>
<br><tt><font size=2>Return explains how to make a simple computation which
returns a specified value.</font></tt>
<br><tt><font size=2>Bind explains how to use the result of a computation
to compute something else.</font></tt>
<br><tt><font size=2>&nbsp; <br>
-Jeff</font></tt>
<br>
<br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">---</span><br>
<br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">This e-mail may contain confidential and/or privileged information. If you </span><br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">are not the intended recipient (or have received this e-mail in error) </span><br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">please notify the sender immediately and destroy this e-mail. Any </span><br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">unauthorized copying, disclosure or distribution of the material in this </span><br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">e-mail is strictly forbidden.</span><br>