[m-users.] Use of length() as function giving unexpected (to me) error

Zoltan Somogyi zoltan.somogyi at runbox.com
Sat Oct 30 15:04:52 AEDT 2021



On Fri, 29 Oct 2021 21:57:35 +0100, "Sean Charles (emacstheviking)" <objitsu at gmail.com> wrote:

> Given that Args and PStrings are lists of different things, I just sought to compare their length:
> 
> args_to_pstrings(Args, [], _, PStrings, !T),
> ( if length(Args) = length(PStrings) then …
> 
> translate.m:174: In clause for predicate `translate_call'/4:
> translate.m:174:   error: ambiguous overloading causes type ambiguity.
> translate.m:174:   Possible type assignments include:
> translate.m:174:   V_27: `int' or `(pred int)'
> translate.m:174:   You will need to add an explicit type qualification to
> translate.m:174:   resolve the type ambiguity. The way to add an explicit type
> translate.m:174:   qualification is to use "with_type". For details see the
> translate.m:174:   "Explicit type qualification" sub-section of the
> translate.m:174:   "Data-terms" section of the "Syntax" chapter of the Mercury
> translate.m:174:   language reference manual.
> ** Error making `Mercury/opts/translate.opt’.
> 
> changing to the predicate form removes the error,
> 
> list.length(Args, L1),
> list.length(PStrings, L2),
> ( if L1 = L2 then …
> 
> Compiles fine. I know that from the error message it seems that I have somehow produced a curried call ?! I am also using the `int` module as well. Just seeking some explanation!

The explanation is in the error message: the compiler does not know
whether each occurrence of length refers to function list.length/1,
in which case e.g. length(Args) is an int, or to predicate list.length/2,
in which case length(Args) is a curried call whose type is "pred int".

The error message also tells you how to fix the problem: add an explicit
type qualification:

( if length(Args) : int = length(PStrings) then ...

Zoltan.


More information about the users mailing list