IO again ....

Fergus Henderson fjh at
Tue Mar 30 08:03:40 AEST 1999

On 29-Mar-1999, Paul Massey <pma at> wrote:
> Since I got caught by this problem (inside my server). Why
> is, for example:
> :- pred io__write_string(string::in,io__state::di,io__state::uo) is det.
> defined in this way ? Shouldn't this really be (not sure of the modes
> required here):
> :- pred io__write_string(string::in,io__state::di,io__res(io__state)::uo) is det.
> for it to be completely logical ? The io__write_string/3 can
> fail due to lack of space, disappearance of the device,
> etc.

I think what you would want is something like this:

	:- pred io__write_string(string::in,io__res::out,
				io__state::di, io__state::uo) is det.

But the answer is no, it doesn't have to be defined that way to be logical.
Mercury only requires implementations to be sound, not complete,
so if for some reason they are unable to fulfil the request,
they are permitted to abort the execution of the program.

> and in the current system there's no way to trap this situation ?

Yes, unfortunately that is correct, currently there's no way of trapping
those errors.

The plan, however, is to have io__write_string and the like throw
exceptions (see extras/exceptions) rather than aborting.
That will allow you to trap the situation by catching the exception.

Fergus Henderson <fjh at>  |  "I have always known that the pursuit
WWW: <>  |  of excellence is a lethal habit"
PGP: finger fjh at        |     -- the last words of T. S. Garp.

More information about the users mailing list