Bulat Ziganshin wrote:
Hello Brian,

Saturday, February 04, 2006, 4:50:44 AM, you wrote:

One question is how to get some kind of "do" notation that would
work well in a strict setting.
The existing "do" notation makes use of lazyness in so far as the
second arg of  >> is only evaluated when needed. Perhaps a new
keyword such as "go" could be used to use >>= instead ie:

If strictness was the default (eg if the language were ML not
Haskell), then in

             putStr "hello" >> putStr (show 1)

both args to >>> would be evaluated before >> was called. Thus
putStr (show 1) would be evaluated before the combined monad is
actually run, which would be wasteful if we were using a monad with
a >> function that only runs the rhs conditionally on the result of
the lhs.
If Haskell were a strict language I think an equivalent for the do
notation would have to lift everything (except the first expression)
and use >>= instead of >>> .

it seems that you misunderstand the monads (or may be i misunderstand
:)

each and every monadic operation is a function! type "IO a" is really
"RealWorld -> (RealWorld,a)" and the same for any other monad. concept
of the monad by itself means carrying "hidden" state from one monadic
operation to the next. that allows to _order_ monadic operations plus
this state used for zillions other things, including state, logs,
fails and so on, so on

exp1 >> exp2 in a strict setting would force exp1 to be evaluated to a monad, exp2 to be evaluated to a monad, then these monads to be combined using >> into another monad, which at some later point would actually be run. But it is this eager evaluation of exp2 into the rhs monad that is the problem, because in the example above, (show 1) would be evaluated during the evaluation of (putStr "hello" >> putStr (show 1)) whereas in Haskell it would only be evaluated when the combined monad is actually run (because it is only at this point that Haskell actually creates the combined monad from the thunk).

Regards, Brian.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to