[m-rev.] for review: --warn-can-fail-functions

Julien Fischer jfischer at opturion.com
Thu Aug 8 09:38:34 AEST 2024


On Thu, 8 Aug 2024 at 01:51, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
>
> On Wed, 7 Aug 2024 16:45:54 +1000, Julien Fischer <jfischer at opturion.com> wrote:
>
> > On Wed, 7 Aug 2024 at 06:53, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
> > >
> > > For review by anyone. I am seeking feedback mainly about
> > > the name and documentation of the new option.
> >
> > The name seems fine; you may want to extend the entry in the NEWS file
> > to explain
> > why this is useful.
>
> I added this paragraph:
>
>   This option is for people who prefer that all functions be total,
>   and that functions that compute a value only in some circumstances
>   (i.e. partial functions) be expressed as predicates instead.

That's fine.

> > > The third attached file lists all the can-fail functions in the standard library.
> > > It would be nice to replace these, probably with predicate versions
> > > (which some of them probably already have), though they would need
> > > a longer process: (a) deprecate by marking as obsolete, (b) wait for a release,
> > > and then (c) delete.
> >
> > We can certainly go ahead and add missing predicates versions and obsolete the
> > function versions now.
>
> I will do that soon, though there is another issue here. I do intend to add obsolete
> pragmas for the partial function versions so that we eliminate calls to them from
> the rest of the Mercury system now, but should we keep them there? That would be
> in effect forcing people to adopt to our preferences.

You could argue that as the language designers, we are in effect
forcing them to adopt
our preferences anyway ;-)

There are a couple of other reasons for removing them:

1. Partial functions do not "play well" with the rest of the standard
library. We do not
provide modes for many of the standard higher-order operations that
work with semidet functions.

2. Consistency within the standard library. We generally provide
predicates for the affected
operations; why are they functions versions of a subset of them as well?

> For us, it should be enough
> to stop using partial functions ourselves; other people can keep using them if they like.
> However, deleting the obsolete pragmas from the library after we have acted on them
> would also *prevent* people who *do* share our preferences from getting the assistance
> of the compiler in following our example. What we would need is a pragma that says
> *warn about call to this function if a specific option is set*, which we don't have.

That's a non-issue IMO.  We are going to remove the partial functions
eventually anyway.

Julien.


More information about the reviews mailing list