[m-dev.] for review: use bitsets in quantification

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 8 00:56:46 AEDT 2000


On 07-Nov-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 07-Nov-2000, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> > I agree with most of what Fergus wrote, but I disagree with this part:
> > 
> > On Tue, Nov 07, 2000 at 03:08:21PM +1100, Fergus Henderson wrote:
> > 
> > > 3.  Although the class is named `enum', the invariants given are not
> > > sufficient for you to actually enumerate the values of the type (or at
> > > least not with reasonable efficiency).  For example, to get the next
> > > value after X in the enumeration sequence, you could try
> > > `from_int(to_int(X) + 1)'.  But there is no guarantee that this call
> > > to `from_int' will succeed.  So I think you should add another invariant:
> > > 
> > > 	all [Int] ((enum_first =< Int, Int =< enum_last) =>
> > > 		some [X] X = from_int(Int)).
> > 
> > As you point out later, this isn't required for sparse_bitset.  I think
> > there are good reasons for making this class as simple as possible.  I would
> > suggest a subclass of enum (maybe called `dense_enum') should have this
> > constraint, and then should have the succ and pred methods etc.  This will
> > often be useful, but I see no reason to exclude types for which this is not
> > the case from using the sparse_set representation.
> 
> I agree with the idea here, but I'd argue about the naming: I think
> the name `enum' should be reserved for something that you can
> efficiently enumerate, and there should be another name
> (`convertable_to_int'?) for something that you can convert to/from
> int.

Actually on second thoughts I disagree with the idea too:
sparse_bitset doesn't strictly require that `to_int' return contiguous
values, but I can't see any practical advantage in defining `to_int'
in a way that doesn't return contiguous values, and so I don't think
this extra flexibility would actually buy you anything.  Hence to
minimize complexity, sparse_bitset should be defined to just use
`enum' rather than `convertable_to_int', and in fact we shouldn't
even define a `convertable_to_int' type class in the standard library.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list