[m-users.] Predicate declared nondet error: mode mismatch in disjunction.

Sean Charles (emacstheviking) objitsu at gmail.com
Thu May 20 21:03:08 AEST 2021


Hi,

I have created a predicate called bifmap/2 that is declared as nondet, as given the same input string, the body of a token, it could produce more than one result as I allow alternative forms in my language eg, “o>” and “emit”, “λ” and “defun” etc. I am trying to implem,ent a help functio for my repl, and the issue I have is again trying to figure out what the compiler is telling me, the error is:

mmc -s hlc.gc -O4 -E --make felt
Making Mercury/int3s/words.int3
Making Mercury/ints/words.int
Making Mercury/cs/words.c
words.m:230: In clause for `bifmap(in, out)':
words.m:230:   mode mismatch in disjunction.
words.m:230:   The variable `HeadVar__2' is ground in 118 out of 119 branches.
words.m:230:   It has the following instantiation states.
words.m:109:     In this branch, `HeadVar__2' has the ground instantiatedness
words.m:109:       unique(binaryop(unique(gt))).
words.m:110:     In this branch, `HeadVar__2' has the ground instantiatedness
words.m:110:       unique(binaryop(unique(lt))).
words.m:111:     In this branch, `HeadVar__2' has the ground instantiatedness
words.m:111:       unique(binaryop(unique(gte))).
words.m:112:     In this branch, `HeadVar__2' has the ground instantiatedness
words.m:112:       unique(binaryop(unique(lte))).
words.m:113:     In this branch, `HeadVar__2' has the ground instantiatedness
words.m:113:       unique(binaryop(unique(neq))).
words.m:114:     In this branch, `HeadVar__2' has the ground instantiatedness
... error log truncated, see `words.err' for the complete log.
** Error making `Mercury/cs/words.c'.
make: *** [felt] Error 1
The terminal process "/bin/zsh '-c', 'make'" terminated with exit code: 2. 

In the words.err file it has listed every single line of my predicate. In this case the disjunction (I think) is the entire set of bifmap/2 declarations. I have attached the complete contents of my source file this time, sorry for the size of it. I am pretty sure I don’t have any duplicates either, this has been a long cut and paste and totally reorganise from my Prolog code so I suspected some kind of cut and paste error could have crept in but if so I have failed to spot it.

I am also assuming that `nondet` is correct for its determinism, I know it CAN fail i.e. a string that is not a keyword and for the examples given above it could succeed more than once.

Thank you
Sean


— words.m —
:- module words.
:- interface.
    % Binary Operator Types
:- type bop_type ---> gt ; lt ; gte ; lte ; neq ; eq_typed ; neq_typed ; eq .
    % Nary Operator Types
    % the _ stops reserved word errors!  :|
:- type nop_type ---> add_ ; sub_ ; mult_ ; div_ ; and_ ; or_ ; mod_ ; bitand_ ; bitor_ ; xor_.
    % Unary op types
:- type uop_type ---> not_.
    % Access Control Levels
:- type acl ---> public ; protected ; private.
    % The complete FELT instruction set
:- type instruction
        --->    pre_when
        ;       alen
        ;       alist
        ;       apop
        ;       apply
        ;       apply_star
        ;       apush
        ;       aref
        ;       array
        ;       as
        ;       ashift
        ;       assign
        ;       aunshift
        ;       binaryop(bop_type)
        ;       break
        ;       cast
        ;       catch_
        ;       class
        ;       classcall
        ;       concat
        ;       const
        ;       constc
        ;       continue
        ;       crash
        ;       cvar(acl)
        ;       decf
        ;       decr
        ;       defclass
        ;       define
        ;       define_star
        ;       defstatic
        ;       defun_pu
        ;       defun_pro
        ;       emit
        ;       lambda
        ;       defun(acl)
        ;       defunc(acl)
        ;       defvar
        ;       false_
        ;       for_
        ;       foreach
        ;       if_
        ;       incf
        ;       include
        ;       include_once
        ;       incr
        ;       instanceof
        ;       interface
        ;       mcall
        ;       methodcall
        ;       mvar(acl)
        ;       my
        ;       naryop(nop_type)
        ;       new
        ;       progn
        ;       require
        ;       require_once
        ;       return
        ;       return_star
        ;       setq
        ;       switch
        ;       throw_
        ;       true_
        ;       try_
        ;       typecast
        ;       typeof
        ;       unaryop(uop_type)
        ;       until
        ;       while.

:- pred bifmap(string::in, instruction::out) is nondet.

:- implementation.
:- import_module list, string.
    %
    % Built-In Function (bif) map.
    % This predicate contains a mapping from the input string in the left to
    % the actual reserved word on the right. It can be used as a bidirectional
    % mapping but for now it is one way only.
    %
bifmap(">",binaryop(gt)).
bifmap("<",binaryop(lt)).
bifmap(">=",binaryop(gte)).
bifmap("<=",binaryop(lte)).
bifmap("!=",binaryop(neq)).
bifmap("===",binaryop(eq_typed)).
bifmap("!==",binaryop(neq_typed)).
bifmap("==",binaryop(eq)).  % some targets allow this

bifmap("+",naryop(add_)).
bifmap("-",naryop(sub_)).
bifmap("*",naryop(mult_)).
bifmap("/",naryop(div_)).
bifmap("%",naryop(mod_)).
bifmap("&",naryop(bitand_)).
bifmap("|",naryop(bitor_)).

bifmap("#f:when(",pre_when).

bifmap("alen",alen).
bifmap("@#",alen).
bifmap("alist",alist).
bifmap("and",naryop(and_)).
bifmap("&&",naryop(and_)).
bifmap("apop",apop).
bifmap("apply",apply).
bifmap("apply*",apply_star).
bifmap("apush",apush).
bifmap("@>",apush).
bifmap("aref",aref).
bifmap("@",aref).
bifmap("@<",apop).
bifmap("array",array).
bifmap("as",as).
bifmap("ashift",ashift).
bifmap(">@",ashift).
bifmap("assign",assign).
bifmap("=",assign).
bifmap("aunshift",aunshift).
bifmap("<@",aunshift).
bifmap("break",break).
bifmap("cast",cast).
bifmap("class",class).
bifmap("class-call",classcall).
bifmap("::",classcall).
bifmap("concat",concat).
bifmap(".",concat).
bifmap("const",const).
bifmap("constc",constc).
bifmap("continue",continue).
bifmap("crash",catch_).
bifmap("cvar",cvar(public)).
bifmap("cvar#",cvar(protected)).
bifmap("cvar+",cvar(public)).
bifmap("cvar-",cvar(private)).
bifmap("decf",decf).
bifmap("--",decf).
bifmap("decr",decr).
bifmap("defclass",defclass).
bifmap("define",define).
bifmap("define*",define_star).
bifmap("defstatic",defstatic).
bifmap("defun",defun(public)).
bifmap("λ",defun(public)).
bifmap("λ*",lambda).
bifmap("defun#",defun(protected)).
bifmap("defun*",lambda).
bifmap("defun+",defun(public)).
bifmap("defun-",defun(private)).
bifmap("defunc",defunc(public)).
bifmap("defunc#",defunc(public)).
bifmap("defunc+",defunc(protected)).
bifmap("defunc-",defunc(private)).
bifmap("defvar",defvar).
bifmap(":=",defvar).
bifmap("o>",emit).
bifmap("emit",emit).
bifmap("false",false_).
bifmap("#f",false_).
bifmap("for",for_).
bifmap("foreach",foreach).
bifmap("function",defun(public)).
bifmap("function*",lambda).
bifmap("functionc",defstatic). % CHECK!
bifmap("if",if_).
bifmap("incf",incf).
bifmap("++",incf).
bifmap("include",include).
bifmap("include-once",include_once).
bifmap("incr",incr).
bifmap("instanceof",instanceof).
bifmap("interface",interface).
bifmap("lambda",lambda).
bifmap("mcall",methodcall).
bifmap("->",methodcall).
bifmap("mvar",mvar(public)).
bifmap("mvar#",mvar(protected)).
bifmap("mvar+",mvar(public)).
bifmap("mvar-",mvar(private)).
bifmap("my",my).
bifmap("new",new).
bifmap("not",unaryop(not_)).
bifmap("!",unaryop(not_)).
bifmap("¬",unaryop(not_)).
bifmap("or",naryop(or_)).
bifmap("||",naryop(or_)).
bifmap("progn",progn).
bifmap("require",_).
bifmap("require-once",require_once).
bifmap("return",return).
bifmap("return*",return_star).
bifmap("setq",setq).
bifmap("switch",switch).
bifmap("throw",throw_).
bifmap("true",true_).
bifmap("#t",true_).
bifmap("try",try_).
bifmap("typeof",typeof).
bifmap("until",until).
bifmap("while",while).
bifmap("xor",naryop(xor_)).
bifmap("^",naryop(xor_)).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20210520/65fd11ca/attachment-0001.html>


More information about the users mailing list