[m-users.] Usage of inst subtypes with list.foldl in rotd

Paul Bone paul at bone.id.au
Tue Mar 3 11:09:44 AEDT 2015

On Sun, Mar 01, 2015 at 08:29:47PM +0100, Dirk Ziegemeyer wrote:
> Dear,
> during migrating my app from mercury version 14.01.1 to rotd-2015-02-20, I discovered that I can’t use list.foldl any more with inst subtypes.
> Julien noticed already that some parts of the mode checker have been tightened up and that this would require some modifications in my code.
> As a workaround I use foldl with a slightly different mode declaration:
> Instead of:
> :- mode foldl(pred(in, in, out) is det, in, in, out) is det.
> This mode declaration solved the issue:
> :- mode foldl(pred(in(I0), in(I1), out(I1)) is det,
>               in(list(I0)), in(I1), out(I1)) is det.

Yes, the mode analysis has been made "tighter", in other words it does a
better job of enforcing correctness and rejecting mode-incorrect programs.

> Is there a way, I could use list.foldl from the standard library again?

Not that I know of.  I wouldn't recommend this either as your program was
always mode-incorrect but the compiler didn't do a very good job of telling
you.  I agree that it is uncomfortable that this is now incompatible.

I suggest creating your own mode-polymorphic foldl predicate, similar to
what you have done, and making it part of your application.  You will
probably need to name it something other than foldl so I suggest

The long term solution to this is to make the predicates in the standard
library mode-polymorphic.  The legend (it was before I joined the project)
is that when we tried this mode analysis was too slow and the costs
outweighed the benefits.  Someone ought to correct me if I'm wrong.


Paul Bone

More information about the users mailing list