[m-dev.] for review: use bitsets in quantification
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Nov 8 20:10:33 AEDT 2000
On 08-Nov-2000, schachte at cs.mu.OZ.AU <schachte at cs.mu.OZ.AU> wrote:
> Would it be possible to create a subclass of enum, say int_enum, where
> this is defined to have mode
>
> bitmask(T::in, int:out(bound(0)), int:out)
Derived type classes can't add new modes to base class methods.
But you can easily define a new procedure that does the same thing,
e.g. bitmask/2 rather than bitmask/3.
> >>> Let me turn the question around: why do you want prev and next?
> >>
> >> Because I want `enum's to be enumerable. I'd like to move the `..`
> >> function from library/int.m to library/enum.m and make it work on any
> >> type which is an instance of `enum'.
>
> That would be nice, but I'm not sure that's a good enough motivation
> for making this type class (whatever you want to call it) less general
> than it could be.
But I'm not making it less general.
Anything which you could make an instance of `reversible_hash' (or
`convertable_to_int' or whatever you want to call it)
can also be made an instance of `enum', just by defining an
appropriate `enum__to_int' and `enum__from_int' functions.
It's always possible to map any subset of int into a contiguous
subset of int, and in most cases this should be fairly easy.
At worst the cost will be (a) the need to write those functions,
and (b) some performance penalty if code that would be satisfied with
a `reversible_hash__to_int' ends up using `enum__to_int' instead
because we didn't define a reversible_hash type class in the
standard library.
> Come to think of it, what you need for this is more than just
> `enumerable', you need `enumerable in order'. This implies the type
> has a total order relation, so it should really be in the `comparable'
> class as well.
Hmm, another good point. I guess the notation X `..` Y does imply an
ordering.
OK, I'll give up on `..` for now, and go back to just wanting to be
able to support a dense_bitset type. For that type, I need `first'
and `last' methods. I guess it doesn't strictly *need* contiguous
to_int values, though.
--
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