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

schachte at cs.mu.OZ.AU schachte at cs.mu.OZ.AU
Wed Nov 8 19:40:20 AEDT 2000


On  8 Nov, I wrote:

> Take the base 2 log, and then shift 1 left that many places to get the
> value to OR into the bitset?
> That's a pretty long, inefficient way to compute an identity function.

...

Sorry about that.  I accidentally hit the send key before I was ready.

>>> (To make such types efficiently usable in bitsets, it might be a
>>> good idea to make the predicate/function that maps between value and
>>> the various needed masks be a method of this class.)
>> 
>> Yep.  Something like this:
>> 
>> 	typeclass enum where [
>> 		...
>> 		pred bitmask(T::in, int::out, int::out) is det,
>> 		% This should have the following semantics:
>> 		%	bitmask(Enum, IntNum, BitMask) <=> (
>> 		% 		Val = to_int(Enum),
>> 		% 		IntNum = Val `div` int__bits_per_int,
>> 		% 		BitNum = Val `mod` int__bits_per_int,
>> 		% 		BitMask = 1 << BitNum
>> 		% 	).
>> 	].

Just so.

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)

>>> 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.

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.

-- 
Peter Schachte                     The use of COBOL cripples the mind; its
mailto:schachte at cs.mu.OZ.AU        teaching should, therefore, be regarded
http://www.cs.mu.oz.au/~schachte/  as a criminal offense.
PGP: finger schachte at 128.250.37.3      -- E. W. Dijkstra 

--------------------------------------------------------------------------
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