[m-users.] basic newbie-friendly example needed

Mark Brown mark at mercurylang.org
Thu Sep 3 21:12:49 AEST 2015

On Wed, Sep 2, 2015 at 10:54 AM, Tomas By <tomas at basun.net> wrote:
> I don't think this demonstrates many of Mercury's features, but maybe it
> will take you one step forward.

I think it demonstrates more than you give yourself credit for, namely
that strong modes can help manage performance.

About half of the page is dedicated to discussion of grandfather/2, in
particular the best order for the conjuncts to appear in the body. The
problem it describes is that, no matter what order you choose, there's
some call in which parent/2 has both arguments free. Such a call
performs very badly.

In the Mercury code, an "out, out" mode for parent/2 has not been
declared. The compiler has to reorder the body of grandparent so that
parent/2 is never called with both arguments free. Hence, for this
example, the badly performing call never occurs.


More information about the users mailing list