[Haskell-cafe] Composing functions with runST

Yitzchak Gale gale at sefer.org
Thu Jan 4 04:25:41 EST 2007


Seth Gordon wrote:
> From a friendliness-to-newbies point of view,
> these error messages are a tremendous wart...
> Eeeww.

Neil Mitchell wrote:
> If the interface for some feature requires rank-2
> types I'd call that an abstraction leak in most cases.

As the original poster of this thread, the one who was
bitten this time, let me point out that the use of
rank-2 polymorphism here is actually really nice.
It provides a strong safety guarantee for the ST monad
at *compile time*.

But the protection is a bit heavy-handed, so there are some
painful side effects that need to be addressed.

One is the confusion caused by the strange semantics
to those not familiar with the theory. That should be fixed
by simple, prominant, task-oriented documentation.
("You must always provide runST with an argument. So,
for example, you cannot write "runST $" or "runST .".)

And yes, perhaps the error messages in GHC could be
improved for newbies, but that was never intended to be the
strong point of GHC. I think Hugs is fine here.

The other is awkwardness in extending the capabilites
of ST. For that, I would propose that the function "unsafeRunST"
be added to the library.

Of course, if there is some way to improve both of these
situations by compilers relaxing the restrictions on rank-2
types somewhat, that would be great. But that is probably for
the future.

-Yitz


More information about the Haskell-Cafe mailing list