[m-users.] Confusion over try goal determinism.

Sean Charles (emacstheviking) objitsu at gmail.com
Sun Nov 19 10:50:08 AEDT 2023


I have these defined as exceptions that can be thrown in my code:

:- type stack_error
    --->    stack_depth(int, int)       % need N values, only had M.
    ;       stack_type_int(string)      % wanted int, got a U
    ;       compile_time_word(string)   % can't be used in interp mode.
    ;       interpret_time_word(string) % expected to be interpreting.
    .

In my main execution code, I have predicate that I want to loop, catch any exceptions and then just rinse-repeat until the user ends the session:

    171 :- pred merth_session(mstate::in, mstate::out, io::di, io::uo) is det.
    172 
    173 merth_session(!S, !IO) :-
    174     try [ io(!IO) ]
    175         % promise_equivalent_solutions [!S, !IO]
    176         merth_session_(!S, !IO)
    177     then
    178         merth_session(!S, !IO)
    179 
    180     catch stack_depth(X, Y) ->
    181         console_error("Stack depth! %i %i", [ i(X), i(Y)], !IO)
    182 
    183     catch stack_type_int(T) ->
    184         console_error("Wrong type, int expected, got %s",
    185             [ s(string(T)) ], !IO)
    186 
    187     catch compile_time_word(Word) ->
    188         console_error("%s is compile time only", [ s(Word) ], !IO)
    189 
    190     catch interpret_time_word(Word) ->
    191         console_error("%s is interpret time only", [ s(Word) ], !IO).

The compiler error is:

merth.m:171: In `merth_session'(in, out, di, uo):
merth.m:171:   error: determinism declaration not satisfied.
merth.m:171:   Declared `det', inferred `multi'.
merth.m:171:   The reason for the difference is the following.
merth.m:174:   Call to
merth.m:174:   `exception.magic_exception_result'(out((exception.cannot_fail)))
merth.m:174:   can succeed more than once.
merth.m:174: Error: call to predicate `exception.magic_exception_result'/1 with
merth.m:174:   determinism `cc_multi' occurs in a context which requires all
merth.m:174:   solutions.


In the user manual, seciton 14, Exception handling, at the top it says:

	Goal must have one of the following determinisms: det, semidet, cc_multi, or cc_nondet.

And then further down it says:

	A try goal has determinism cc_multi.

I am just a little confused at this point as to what I am being told by the compiler, I can't even see 'magic_exception' so it's inferred something perhaps? Do I need a catch_any, that's optional though?

Thanks.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20231118/db0c7f5c/attachment.html>


More information about the users mailing list