[m-users.] Ambiguous overloading error, with_type suggested

Sean Charles (emacstheviking) objitsu at gmail.com
Sat Jun 12 18:50:00 AEST 2021


The error:
ast.m:042: In clause for predicate `on_lexer'/1:
ast.m:042:   error: ambiguous overloading causes type ambiguity.
ast.m:042:   Possible type assignments include:
ast.m:042:   Tokens: `pred(list.list(lexer.token), list.list(lexer.token))' or
ast.m:042:   `(pred list.list(lexer.token))'
ast.m:042:   You will need to add an explicit type qualification to resolve the
ast.m:042:   type ambiguity. The way to add an explicit type qualification is
ast.m:042:   to use "with_type". For details see the
ast.m:042:   "Explicit type qualification" sub-section of the "Data-terms"
ast.m:042:   section of the "Syntax" chapter of the Mercury language reference
ast.m:042:   manual.

the ast.m code:

[42]on_lexer(Lx) :-
      Tokens = list.filter(
          % is_comment,
          (pred(T::in) is semidet :- Ty = tok_type(T), not (Ty = c1 ; Ty = cn)),
          tokens(Lx)
      ),

      trace[io(!Dbg), runtime(env("FELT_AST"))]
      (atrace(0, "on_lexer: input tokens:\n%s\n",
          [s(string(Tokens))], !Dbg)),

      true.


the predicate tokens is an auto generated field accessor from my lexer state record:
:- type lexcon
        --->    lexcon(
                    buf        :: string,
                    status     :: lexer_status,
                    prev_char  :: maybe(char),
                    buf_pos    :: location,
                    tab_size   :: int,
                    str_delim  :: char,
                    tok_start  :: location,
                    tokens     :: list(token)
        ).


Sadly, I just cannot understand what I have done wrong to create ambiguity. tokens/1 returns list(token), given:

:- type location
        --->    pos(index::int, line::int, col::int).
:- type token
        --->    tk(location, string)
        ;       op(location) ; cp(location)
        ;       ol(location) ; cl(location)
        ;       om(location) ; cm(location)
        ;       c1(location, string) ; cn(location, string)
        ;       s1(location, string) ; s2(location, string)
        .

Thanks again,
Sean.

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


More information about the users mailing list