[bitc-dev] BitFields and Integral typeclass

Swaroop Sridhar swaroop.sridhar at gmail.com
Sat May 20 01:24:52 EDT 2006


Jonathan S. Shapiro wrote:
> On Fri, 2006-05-19 at 18:43 -0400, Swaroop Sridhar wrote:
> 
>>In order to deal with bitfields, I must write a huge number of instances.
>>
>>(definstance (Integral (bitfield  int8 1)))
>>(definstance (Integral (bitfield uint8 1)))
>>(definstance (Integral (bitfield  int8 2)))
>>(definstance (Integral (bitfield uint8 2)))
>>...
>>...
>>
>>totally 508 instances
>>...
>>...
>>(definstance (Integral (mutable (bitfield  int64 63))))
>>(definstance (Integral (mutable (bitfield uint64 63))))
>>
>>
>>This might be another case that motivates literal classes (singleton 
>>types). Although -- I think -- to a lesser extent than the case of arrays.

> Actually, I'm not convinced that bitfields should be a member of
> Integral at all.

They must be, for the sake of assignment from integer literals.

For example,

(defstruct st a:(bitfield int32 18) b:(bitfield int32 14))

(st 0 1)

The 0 and 1 get the type (Integral 'a) => 'a by default, and they must 
unify with the bitfield type in this case.


Swaroop.


More information about the bitc-dev mailing list