[bitc-dev] BitFields and Integral typeclass
Swaroop Sridhar
swaroop at cs.jhu.edu
Fri May 19 18:43:39 EDT 2006
I was writing the instances for the integral typeclass:
(deftypeclass (Integral 'a))
For fixed precision primitive integers, the following are the instances
(I do not have any methods for now):
(definstance (Integral int8))
(definstance (Integral uint8))
(definstance (Integral int16))
(definstance (Integral uint16))
(definstance (Integral int32))
(definstance (Integral uint32))
(definstance (Integral int64))
(definstance (Integral uint64))
(definstance (Integral (mutable int8)))
(definstance (Integral (mutable uint8)))
(definstance (Integral (mutable int16)))
(definstance (Integral (mutable uint16)))
(definstance (Integral (mutable int32)))
(definstance (Integral (mutable uint32)))
(definstance (Integral (mutable int64)))
(definstance (Integral (mutable uint64)))
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.
My expectation is that bitfields should be used in low level structures,
and no other class should have all of these instances. If they do, they
can always inherit the Integral typeclass. Also, it is possible to
construct a tree of typeclasses for the bitfields obtainable from
different types which are all inherited by the Integral typeclass.
So, for now I have put in all these instances, and I think we should go
with them.
Thanks,
Swaroop.
More information about the bitc-dev
mailing list