[GHC] #14839: Bits typeclass law for LSB

#14839: Bits typeclass law for LSB -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Keywords: base | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The documentation for the `Bits` typeclass claims:
Bits are numbered from 0 with bit 0 being the least significant bit.
However, there's no law specified in the typeclass that enforces this. I realized this recently because I've been adding the laws for `Bits` to a library of property tests I maintain: http://hackage.haskell.org/package /quickcheck-classes-0.3.3/docs/Test-QuickCheck-Classes.html#v:bitsLaws In another package of mine, someone requested to add a `Bits` instance for a type but with the MSB considered bit 0. (https://github.com/andrewthad /haskell-ip/issues/29) I thought this would fail to satisfy a law of `Bits`, but it doesn't. So at the least, I was thinking we could add the following laws to `FiniteBits`: {{{ countTrailingZeros (bit 0) = 0 countLeadingZeros (bit 0) = finiteBitSize undefined - 1 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14839 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14839: Bits typeclass law for LSB -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: base Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: core-libraries-committee@… (added) * milestone: => 8.6.1 Comment: This is likely a job for the CLC. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14839#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14839: Bits typeclass law for LSB -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: base Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Have you ran this past the libraries mailing list? On the surface, this seems reasonable to me, but perhaps I'm forgetting some obscure `Bits` instance that doesn't satisfy this property. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14839#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC