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

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


Am Samstag, dem 30.10.2021 um 17:31 +1100 schrieb Zoltan Somogyi:
> 
> 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

Would that slow things down that much? I think MMC is quite fast, much
faster than, say, the Glasgow Haskell Compiler. There is room for some
slowdown. Of course, it would be an effort to modify MMC...

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

Bye,
Volker

-------------- 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/54c611b2/attachment.sig>


More information about the users mailing list