Re: Proposal: Determining whether a Bits instance is FiniteBits
Edward Kmett <[email protected]>
| Newsgroups | gmane.comp.lang.haskell.libraries |
|---|---|
| Message-ID | <CAJumaK9O50M-eOZv3UCFtG7cWVK7C9_sSUnb4N8pFt611GBWAQ@mail.gmail.com> |
This does seem like a strict improvement over the status quo. Users can then conditionally get access to count(Trailing|Leading)Zeros by refining the type information available to them using this combinator, which offers a bunch of bit twiddling usecases. -Edward On Tue, May 18, 2021 at 9:30 AM Zemyla <[email protected]> wrote: > Every Bits instance has to know that whether it's a FiniteBits > instance as well, due to bitSizeMaybe. Therefore, it should also be > able to tell a program that it is in fact a FiniteBits instance. There > should be a function added to Data.Bits.Bits: > > withFiniteBits :: Bits a => a -> (FiniteBits a => r) -> r -> r > > The default should be withFiniteBits _ _ x = x, at least for the next > several versions. bitSizeMaybe can be defined as > > bitSizeMaybe x = withFiniteBits x (Just (finiteBitSize x)) Nothing > > once everyone is on board with properly defining the value. > _______________________________________________ > Libraries mailing list > [email protected] > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries > _______________________________________________ Libraries mailing list [email protected] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries