[m-rev.] for post-commit review: improve bag.m

Zoltan Somogyi zoltan.somogyi at runbox.com
Thu Sep 17 21:37:33 AEST 2015



On Thu, 17 Sep 2015 13:35:43 +1000 (AEST), Julien Fischer <jfischer at opturion.com> wrote:
> >      % Compares the two bags, and returns whether the first bag is a
> >      % subset (<), is equal (=), or is a superset (>) of the second.
> > +    % Fails if the two bags are incomparable.
> > +    %
> > +    % Examples:
> >      % subset_compare(<, {apple, orange}, {apple, apple, orange}).
> >      % subset_compare(=, {apple, orange}, {apple, orange}).
> >      % subset_compare(>, {apple, apple, orange}, {apple, orange}).
> > @@ -243,6 +297,8 @@
> >  :- pred subset_compare(comparison_result::out, bag(T)::in, bag(T)::in)
> >      is semidet.
> 
> There's another existing issue here: it's a little unusual to have
> a semidet comparison predicate -- the ordering of the arguments suggests
> that this predicate is intended as such -- so we should at least add
> det_subset_compare (e.g. so that it is possible to call list.sort/3 on
> lists of bags using the subset ordering).

Adding such a predicate won't make it possible to sort a list of bags,
since the probability that one of those calls will throw an exception
will climb very near 1 even with reasonably short lists.

I followed your other suggestions.

Zoltan.





More information about the reviews mailing list