[mercury-users] Exceptions and unique modes

Ralph Becket rbeck at microsoft.com
Fri Feb 16 00:14:01 AEDT 2001


One solution (similar to that used by GHC to handle asynchronous exceptions)
is to ensure that any state you want to persist across exceptions is
attached
to the io__state.

Now, instead of threading some unique X around, you pass the io__state
around
and either ensure that the appropriate procedures know how to access the
relevant part of the io__state or you pass around access functions that will
do the job.

That is, rather than

	X0 = something_unique,
	try(p(X), Result),
	(	Result = exception(E), % where has my unique thing gone?!
		...
	;	...
	)

we write

	attach_to_io_state(something_unique, IO0, IO1),
	try_io(p, Result, IO1, IO2), % p knows how to get at the unique
thing.
	(	Result = exception(E),
		recover_my_unique_thing(X, IO2, IO),
		...
	;	...
	)

I think one problem with this is that the modes are tricky.

Another problem is that if the exception is raised while the unique
attachment is being processed (i.e. the io__state no longer contains
a valid reference) then we can't expect to recover it when we catch
the exception.  How does the compiler and/or runtime detect this case?

If we're prepared to say that any exceptions raised during these points
are lethal then we can make some progress, but it's far from ideal.

This is quite a serious problem for the reasons Peter points out:
robust code has to be able to survive unexpected exceptions and clean
up afterwards.

The Haskell approach doesn't suffer from this problem since they never
pass unique objects around; rather they construct computations on those
objects that are applied at the top level.  Monads for Mercury, anyone?

--
Ralph Becket      |      MSR Cambridge      |      rbeck at microsoft.com 

--------------------------------------------------------------------------
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