[Haskell-cafe] State monad strictness - how?

Yitzchak Gale gale at sefer.org
Wed Jan 10 08:26:30 EST 2007

Hi Bulat,

I wrote:
>> [State and StateT] should be consistent. I
>> would much prefer for them both to be lazy.

Bulat Ziganshin wrote:
> imho, lazy monads (as any other lazy things) is a source of beginner's
> confusion. therefore it may be better to provide "default" monads as strict
> and lazy ones - for one who knows what he wants - with a Lazy prefix, e.g.
> LazyST, LazyState...

Well, as long as both are provided, that is fine with me.

But I do not think that laziness in monad methods is a reason
for beginners' confusion.

First of all, it is natural to get a little confused about strictness
at the beginning. I'm not sure it happens more often with
monads than anywhere else.

If there is more confusion about strictness with monads,
it is because of the fact that many introductions/tutorials
confuse all monads with IO. They say something like:

"So how do you create side effects in the real world? That is
what monads are for."

No, no, no! That is what ** IO ** is for. Most monads are pure!

In fact, I think making the default strict will create more confusion.

We should help beginners to understand right from the start that
do-notation is not a "procedure" of commands for the computer
to carry out. It is just a special syntax for defining functions. We
use it when it is more natural to describe the effect of a function
in a step-by-step style, just as happens sometimes in mathematics.
But the compiler is under no obligation to follow our steps literally.

Except with IO - when dealing with the real world, we need
to be able to specify the exact order in which things happen.

ST represents using physical memory as a fast storage device.
So it is really IO in disguise.


More information about the Haskell-Cafe mailing list