[mercury-users] using 'try' for exception handling

Goncalo Jorge Coelho e Silva l10454 at alunos.uevora.pt
Fri Jun 6 02:23:20 AEST 2003



Hi,

 Fergus' post wasn't too clear for me. I still 
have problems with the predicate, even though I've
made changes to try it:

Fergus wrote:

>> :- pred tryexcept(io__state, io__state). 
>> :- mode tryexcept(di, uo) is det. 
>> %:- pred tryexcept(string ,io__state, io__state). 
>> %:- mode tryexcept(in, di, uo) is det. 

>The commented out version is the one that you need. 

>> main(IO1, IO):- 
>> try_io(tryexcept(IO2, IO3), IO1, IO, Result), 
>> %try_io( tryexcept(IO1, IO), Result), 
>> %try_io( tryexcept("string", IO1, IO), Result), 

>The syntax that you are looking for here is 

>        try_io(try_except, Result, IO1, IO) 




I get:
---------

inter.m:035: In clause for predicate `inter:tryexcept/3':
inter.m:035:   warning: variable `IO_0' occurs only once in this scope.
inter.m:035: In clause for predicate `inter:tryexcept/3':
inter.m:035:   warning: variable `IO' occurs only once in this scope.
inter.m:036: In clause for predicate `inter:tryexcept/3':
inter.m:036:   warning: variable `Int3' occurs only once in this scope.
inter.m:027: In clause for predicate `inter:main/2':
inter.m:027:   in unification of variable `Result'
inter.m:027:   and term `succeeded(IO)':
inter.m:027:   type error in argument(s) of functor `succeeded/1'.
inter.m:027:   Argument 1 (IO) has type `(io:state)',
inter.m:027:   expected type was `string'


with this code:
--------------

:- module inter.

:- interface.

:- import_module io.

:- pred main(io__state, io__state).
:- mode main(di, uo) is det.

:- pred tryexcept(string, io__state, io__state).
:- mode tryexcept(in, di, uo) is det.

%:- pred tryexcept(int ,io__state, io__state).
%:- mode tryexcept(out, di, uo) is det.

:- implementation.

:- import_module string.
:- import_module exception.
:- import_module require.


main(IO1, IO):-
        try_io(tryexcept, Result, IO1, IO),
        %try_io(tryexcept("string"), Result, IO1, IO),
        (
        Result = succeeded(IO) %,
                %io__write_string("22", IO1, IO)
        ;
        Result = exception(_),
                io__write_string(" string__det_to_int Failed! ", IO1, IO)
        ).


tryexcept(String, IO_0, IO):-
        string__det_to_int(String) = Int3.

%tryexcept(Int3, IO_0, IO):-
%       string__det_to_int(String) = Int3.
        %string__det_to_int("D") = Int3.



what's wrong here?

cheers,
Goncalo

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