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

Zoltan Somogyi zoltan.somogyi at runbox.com
Sat Oct 30 17:31:22 AEDT 2021



On Sat, 30 Oct 2021 08:20:11 +0200, Volker Wysk <post at volker-wysk.de> wrote:
> > 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..?

No, you cannot unify a predicate with another predicate. However,
the typechecker, when it looks at "length(Args)", does not know whether
the context allows the type of length(Args) to be a predicate or not,
which is why it reports the error it does.

We *could* modify the compiler to keep track of such contexts, but

- that would slow down every execution of the type checker, i.e. it would
  slow down every compilation, but

- since this kind of ambiguity is reasonably rare in Mercury programs,
  this extra effort would be wasted in the vast majority of cases.

Zoltan.





More information about the users mailing list