[mercury-users] exceptions considered bloody annoying

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Apr 16 19:05:13 AEST 2002


On 15-Apr-2002, Michael Day <mikeday at bigpond.net.au> wrote:
> 
> During the debates relating to a streams design for Mercury a number of
> potential interfaces were scrapped as they didn't work well with
> exceptions. One of the final contenders was with_stream:
> 
> pred with_stream(filename, pred(stream, stream), io, io).
> mode with_stream(in, pred(di, uo) is det, di, uo) is cc_multi.
> 
> or along those lines. It would catch any exceptions thrown by the
> predicate and close files or deallocate resources before rethrowing the
> exception, guaranteeing no leaks.
> 
> It's not an amazing interface, as user code has to be structured
> specifically to use it and it can be awkward to manipulate multiple
> streams at once in an arbitrary fashion. Also it's cc_multi, which
> effectively makes everything cc_multi, and confuses people.

So declare it as `det' rather than `cc_multi'.

`promise_only_solution_io' is there for a reason.
Sometimes you need to use it.  In a case like this,
where you are always rethrowing after you catch,
it is sound to declare the procedure as `det'
and to use `promise_only_solution_io'.

> I have a similar interface to with_stream that looks like this:
> 
> pred with_stuff(pred(stuff, T, T), T, T, io, io).
> mode with_stuff(pred(in, di, uo) is det, di, uo, di, uo) is det.
...
> So, with_stuff has to catch all exceptions and then throw a *different*
> exception, along the lines of "this code threw the following exception".
> 
> And again, everything ends up cc_multi.

Likewise here -- use promise_only_solution_io.

Perhaps this pattern occurs often enough that it should be abstracted
and put into the standard library.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list