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

Volker Wysk post at volker-wysk.de
Sat Oct 30 17:20:11 AEDT 2021


Am Samstag, dem 30.10.2021 um 15:04 +1100 schrieb Zoltan Somogyi:
> 
> 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".

But you can't have a predicate as one of the two things being unificated,
can you? You can't compare a predicate for equality with another
predicate..?

> The error message also tells you how to fix the problem: add an explicit
> type qualification:
> 
> ( if length(Args) : int = length(PStrings) then ...
> 
> Zoltan.
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org
> https://lists.mercurylang.org/listinfo/users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20211030/e6952939/attachment.sig>


More information about the users mailing list