Proposal: Add hasBitSize to Data.Bits.Bits

Edward Kmett ekmett at gmail.com
Mon Aug 13 23:38:40 CEST 2012


On Sun, Jul 29, 2012 at 12:38 PM, Antoine Latter <aslatter at gmail.com> wrote:

> On Sun, Jul 29, 2012 at 11:37 AM, Antoine Latter <aslatter at gmail.com>
> wrote:
> >
> > The downside to this proposal is that the requester (Edward) actually
> > wants a function of type "a -> Maybe Int", so his polymorphic function
> > can handle both infinite bit-types and finite bit-types.
> >
> > With the new class, Edward could write:
> >
> > class BitTraversable i where
> >   traverseBits :: <sometype>
> >
> > instance (BitSize i) => BitTraversable i where
> >   traverseBits = <something>
> >
> > instance BitTraversable Integer where
> >   traverseBits = <something else>
> >
>
> I should add that this approach looks like it would require
> OverlappingInstances.


Correct. This is not a viable solution for the problem, also it precludes
the existance of support for someone else's Natural number type, etc.

Every type that is currently an instance of Bits is either of a fixed size
or potentially infinite.

Changing bitSize to return a Maybe a works. Making a separate BitSize class
simply forces me to do exactly what I'm doing right now, which is ignore it
and manually probe.

I'm a strong -1 vote to any solution that splits BitSize out into a
separate class.

-Edward
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20120813/37486a6e/attachment.htm>


More information about the Libraries mailing list