<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>> The tutorials seriously need to step back and
start with <br>
> something like, "To enforce order of evaluation we evaluate <br>
> closures* returning a defined type. The first closure will feed
<br>
> its result to the second which will in turn feed it's result to <br>
> the third. Since the third closure can't be evaluated without
<br>
> having the results from the second and first (and thus they had <br>
> to be evaluated earlier in time) we get a defined evaluation <br>
> sequence. Here are some examples..."<br>
> </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 (>>=) 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> x :: Int
-- x is an Int</font></tt>
<br>
<br><tt><font size=2> x :: Monad m => m Int -- x
is a computation of an Int</font></tt>
<br>
<br><tt><font size=2> x :: [Int]
-- x is a computation of an Int which can return multiplie
values</font></tt>
<br>
<br><tt><font size=2> x :: Maybe Int
-- x is a computation of an Int which might fail (return Nothing)</font></tt>
<br>
<br><tt><font size=2> x :: State s Int
-- x is a computation of an Int which relies on, and returns (possibly
modified) </font></tt>
<br><tt><font size=2>
-- a value of type s. Note:
State s Int is isomorphic to: s -> (Int,s)</font></tt>
<br>
<br><tt><font size=2> x :: IO Int
-- 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> <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>