[m-rev.] for review: Clarify behaviour of upper bounds functions for array types.
Peter Wang
novalazy at gmail.com
Wed Nov 29 17:41:22 AEDT 2017
Would making 'max' semi-deterministic have been a better choice, or just
annoying in practice? Anyway, it is what we have.
It might be viable still to make array.least_index and array.greatest_index
fail for empty arrays. The names suggest to me that they should always
return valid indices on success, more so than min/max.
Peter
diff --git a/library/array.m b/library/array.m
index 5959b53c0..e6eb94ebe 100644
--- a/library/array.m
+++ b/library/array.m
@@ -152,6 +152,7 @@
:- mode least_index(in) = out is det.
% max returns the upper bound of the array.
+ % Returns -1 for an empty array.
%
:- pred max(array(_T), int).
%:- mode max(array_ui, out) is det.
diff --git a/library/bt_array.m b/library/bt_array.m
index 19e81d1a2..208686125 100644
--- a/library/bt_array.m
+++ b/library/bt_array.m
@@ -54,6 +54,7 @@
:- func min(bt_array(_T)) = int.
% Returns the upper bound of the array.
+ % Returns lower bound - 1 for an empty array.
%
:- pred max(bt_array(_T)::in, int::out) is det.
:- func max(bt_array(_T)) = int.
diff --git a/library/version_array.m b/library/version_array.m
index 8c5729e43..ec42bc581 100644
--- a/library/version_array.m
+++ b/library/version_array.m
@@ -144,6 +144,7 @@
:- func size(version_array(T)) = int.
% max(Z) = size(A) - 1.
+ % Returns -1 for an empty array.
%
:- func max(version_array(T)) = int.
More information about the reviews
mailing list