[m-users.] Determinism woes...

emacstheviking objitsu at gmail.com
Fri Jul 5 09:09:14 AEST 2019


Spoke too soon! FUll source and error output....it's beyond my little bear
brain this time of night...I thought that by declaring char_type as
cc_multi the compiler would NOT think it would have multiple solutions as I
committed to the first one as the only solution?!?!

fl1.m:020: In `char_loop'(di, uo):
fl1.m:020:   error: determinism declaration not satisfied.
fl1.m:020:   Declared `det', inferred `multi'.
fl1.m:027:   Call to `fl1.char_type'(in, out) can succeed more than once.
fl1.m:027: Error: call to predicate `fl1.char_type'/2 with determinism
fl1.m:027:   `cc_multi' occurs in a context which requires all solutions.
** Error making `Mercury/cs/fl1.c'.

and the code

    :- pred char_loop(io::di, io::uo) is det.
    char_loop(!IO) :-
        read_char(C, !IO),
        (
            C = eof
        ;
            C = ok(C2),
            char_type(C2, CType),
            chartype_s(CType, CTypeStr),
            format("%c %d %s\n", [c(C2), i(char.to_int(C2)), s(CTypeStr)],
!IO),
            char_loop(!IO)
        ;
            C = error(ErrorCode),
            io.format("%s...\n", [s(io.error_message(ErrorCode))], !IO)
        ).

:- type chartype
    --->    p_open
    ;       p_close
    ;       c_general.

:- pred char_type(char::in, chartype::out) is cc_multi.
char_type(')', p_open).
char_type('(', p_close).
char_type(_, c_general).

:- pred chartype_s(chartype::in, string::out) is det.
chartype_s(p_open, "general").
chartype_s(p_close, "popen").
chartype_s(c_general, "pclose").

Going to sleep on it...

On Thu, 4 Jul 2019 at 23:46, emacstheviking <objitsu at gmail.com> wrote:

> Thanks Richard!
>
> That is so obvious when you see it. I am thinking like a Haskell hacker
> this evening for sure.
> I changed it to "cc_multi" and it compiled ANd did what I expected /
> wanted.
>
> In my prolog code I have a cut after each match to commit (cc_multi!!!) to
> that and no more....OMG (trust me I have to be desparate to even think that
> acronym) it really does match !!! I am going to stick that response on a
> post-it under my monitor for a whole month!
>
> Currently re-reading section 6 of the manual...sigh...these are the times
> when I just know that a formal education might have helped me stumble and
> fall a little less.
>
> Thanks again,
> Sean.
>
>
>
> On Thu, 4 Jul 2019 at 23:40, Richard O'Keefe <raoknz at gmail.com> wrote:
>
>> char_type(')', p_open).
>> char_type('(', p_close).
>> char_type(_, c_general).
>>
>> ')' matches two clauses, the first and last.
>> '(' matches two clauses, the second and last.
>>
>> On Fri, 5 Jul 2019 at 10:24, emacstheviking <objitsu at gmail.com> wrote:
>>
>>> To paraphrase Neo, "I know Prolog".
>>>
>>> but I don't know Mercury and I am struggling to figure out this
>>> error....I am porting some old SWI code and it boils down to the fact that
>>> I obvuisly don't truly understand what "det" means! Here is the code both
>>> as discrete disjunctive clauses and a single big disjunct:
>>>
>>> :- pred char_type(char::in, chartype::out) is det.
>>>
>>> char_type(')', p_open).
>>> char_type('(', p_close).
>>> char_type(_, c_general).
>>>
>>> char_type(C, T) :-
>>>     (
>>>         C = '(', T = p_open
>>>     ;   C = ')', T = p_close
>>>     ;   C = _,   T = c_general
>>>     ).
>>>
>>> and here is the compiler output:
>>>
>>> fl1.m:049: In `char_type'(in, out):
>>> fl1.m:049:   error: determinism declaration not satisfied.
>>> fl1.m:049:   Declared `det', inferred `multi'.
>>> fl1.m:056:   Disjunction has multiple clauses with solutions.
>>>
>>> Now...I understand why (I think) this happens: it's because the final
>>> matching disjuny can match more than one character value hence the multiple
>>> (multi) classification by the compiler BUT he calling loop seeks merely to
>>> convert a character into a character type.
>>>
>>> Is this "cc_multi" in disguise as if the character is not one of the
>>> ones explicitly tested for then I will commit to the first choice as it
>>> will be a "general" character i.e. one with no special meaning to my little
>>> lexer.
>>>
>>> Thank you,
>>> Sean.
>>>
>>> _______________________________________________
>>> users mailing list
>>> users at lists.mercurylang.org
>>> https://lists.mercurylang.org/listinfo/users
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20190705/6e0d6088/attachment.html>


More information about the users mailing list