Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#7135 closed feature request (wontfix)

Data.Bits can still have default implementations for testBit, bit, and popCount by using -XDefaultSignatures

Reported by: joeyadams Owned by:
Priority: normal Milestone: 7.6.1
Component: libraries/base Version: 7.7
Keywords: Cc: jwlato@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


In commit f99cee0 of the base package, the Num constraint was removed from the Bits class. Because the default implementations of testBit, bit, and popCount required Num, the same commit made them external functions instead.

We can still have default implementations for these if we use the -XDefaultSignatures GHC extension:

    default bit :: Num a => Int -> a
    bit = bitDefault

    default testBit :: Num a => a -> Int -> Bool
    testBit = testBitDefault

    default popCount :: Num a => a -> Int
    popCount = popCountDefault

Whether we want to do this or not, I'm not sure.


  • This is more convenient.
  • This may prevent people from encountering runtime errors in existing code that does not have bit, testBit, and popCount implementations, where the author forgot to compile with -Wall .


  • Users get away with writing less portable code, so those who do wish to use non-GHC will have more support work to do.

The attached patch adds defaults for testBit, bit, and popCount, for GHC only. It does not update the documentation, though, so "Minimal complete definition" as-is would be misleading.

P.S.: This ticket is for GHC 7.6.1-rc1. That version tag is not available, though.

Attachments (1)

0001-Data.Bits-Use-XDefaultSignatures-to-have-default-ins.patch (1.2 KB) - added by joeyadams 5 years ago.
Data.Bits: Use -XDefaultSignatures to have default instances for bit, testBit, and popCount

Download all attachments as: .zip

Change History (8)

Changed 5 years ago by joeyadams

Data.Bits: Use -XDefaultSignatures to have default instances for bit, testBit, and popCount

comment:1 Changed 5 years ago by joeyadams

Component: Runtime Systemlibraries/base

comment:2 Changed 5 years ago by pcapriotti

difficulty: Unknown
Milestone: 7.6.1
Status: newpatch
Version: 7.7

The patch looks good, thanks.

comment:3 Changed 5 years ago by igloo

Resolution: wontfix
Status: patchclosed

We discussed using this extension at the time, e.g. in but decided against it.

comment:4 Changed 5 years ago by jwlato

I would request that you reconsider this decision. popCount was only added to the Bits class in base-4.5, which means that now Bits implementors are stuck in the following undesirable position:

  1. omit popCount, which may lead to runtime crashes if popCount is used in programs compiled with ghc-7.6 2. define popcount and drop support for ghc < 7.4 / base < 4.5\ 3. use CPP or cabal trickery to support ghc-7.2, ghc-7.4, and ghc-7.6

For users who wish to support the three most recent ghc versions, none of these are good options.

Upon reading the thread in libraries, I don't believe that anyone realized this issue at the time.

comment:5 Changed 5 years ago by jwlato

Cc: jwlato@… added
Resolution: wontfix
Status: closednew

Apologies, I meant to re-open this issue before and forgot. I'm re-opening due to the issue described in my 2012-08-14 comment.

comment:6 Changed 4 years ago by igloo

Resolution: wontfix
Status: newclosed

I still think the decision was right. If you disagree, please make a new proposal on the libraries list.

Note: See TracTickets for help on using tickets.