Re: [m-users.] Confusion over try goal determinism.
Julien Fischer <[email protected]> Sun, 19 Nov 2023 13:45:48 +1100 (AEDT)
| Newsgroups | gmane.comp.lang.mercury.general |
|---|---|
| Message-ID | <[email protected]> |
On Sat, 18 Nov 2023, Sean Charles (emacstheviking) wrote:
> 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.
"Goal" here means the goal _inside_ the try (i.e the one that you're
trying to catch any exceptions from).
> And then further down it says:
>
> A try goal has determinism cc_multi.
"try goal" means the entire try ... then ... catch etc. construct.
> 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?
What the compiler is trying to tell is that merth_session/4 should have
determinism cc_multi (because the try goal in its body has determinism
cc_multi).
The stuff about the magic_exception_result arises from the
source-to-source transformation that is used to implement try goals.
Julien.
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users