Opened 21 months ago

Closed 20 months ago

Last modified 20 months 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 Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

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:

#ifdef __GLASGOW_HASKELL__
    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
#endif

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

Pro:

  • 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 .

Con:

  • 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 21 months ago.
Data.Bits: Use -XDefaultSignatures to have default instances for bit, testBit, and popCount

Download all attachments as: .zip

Change History (8)

Changed 21 months ago by joeyadams

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

comment:1 Changed 21 months ago by joeyadams

  • Component changed from Runtime System to libraries/base

comment:2 Changed 21 months ago by pcapriotti

  • Difficulty set to Unknown
  • Milestone set to 7.6.1
  • Status changed from new to patch
  • Version set to 7.7

The patch looks good, thanks.

comment:3 Changed 21 months ago by igloo

  • Resolution set to wontfix
  • Status changed from patch to closed

We discussed using this extension at the time, e.g. in http://www.haskell.org/pipermail/libraries/2011-October/016909.html but decided against it.

comment:4 Changed 20 months 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 20 months ago by jwlato

  • Cc jwlato@… added
  • Resolution wontfix deleted
  • Status changed from closed to new

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 20 months ago by igloo

  • Resolution set to wontfix
  • Status changed from new to closed

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.