[m-dev.] for review: use bitsets in quantification
Ralph Becket
rbeck at microsoft.com
Tue Nov 7 21:57:49 AEDT 2000
>From Peter Schachte on 07/11/2000 06:07:43
>
> 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 that the solution here would be to have a range of specialised
typeclasses. Several constraints have been discussed on this thread:
* bounded enumerable types isomorphic to (a subset of) int
:- typeclass enum(T) where [
func to_int(T) = int,
func from_int(int) = T is semidet
].
* (unbounded) enumerable types isomorphic to (a subset of) integer
* enumerable types isomorphic to all ints/integers
:- typeclass complete_enum(T) <= enum(T) where [
% all [X:int] some [Y:T] Y = from_int(X)
].
* enumerable types isomorphic to a contiguous subset of int/integer
:- typeclass contiguous_enum(T) <= enum(T) where [
% all [X:T, Y:T, N:int]
% (to_int(X) =< N, N =< to_int(Y)) =>
% some [Z:T] Z = from_int(N)
].
* enumerable types isomorphic to an arbitrary subset of int/integer
* enumerable types with a lower bound
:- typeclass lb_enum(T) <= enum(T) where [
func min = T
].
* enumerable types with an upper bound
:- typeclass ub_enum(T) <= enum(T) where [
func max = T
].
* enumerable types with both an upper and lower bound
:- typeclass bounded_enum(T) <= (lb_enum(T), ub_enum(T)) where [].
I like Fergus' suggestion of using `enum' for int enumerations and
`enumerable' for integer enumerations.
Ralph
--
Ralph Becket | MSR Cambridge | rbeck at microsoft.com
--------------------------------------------------------------------------
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