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

Sean Charles (emacstheviking) objitsu at gmail.com
Sat Oct 30 18:17:05 AEDT 2021


Zoltan, succinct as always, thank you.
Julien, I didn’t know same_length existed!

Now and then over a coffee I do use mmc-doc and pick a module to study for ten minutes…perhaps 15 minutes from now no.

Again, thanks all, Mercury continues to delight!

Sean


> On 30 Oct 2021, at 05:04, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
> 
> 
> 
> On Fri, 29 Oct 2021 21:57:35 +0100, "Sean Charles (emacstheviking)" <objitsu at gmail.com <mailto: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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20211030/61f597a3/attachment-0001.html>


More information about the users mailing list