Ticket #7135 (closed feature request: wontfix)

Opened 9 months ago

Last modified 8 months ago

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

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

Change History

Changed 9 months ago by joeyadams

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

Changed 9 months ago by joeyadams

  • component changed from Runtime System to libraries/base

Changed 9 months ago by pcapriotti

  • status changed from new to patch
  • difficulty set to Unknown
  • version set to 7.7
  • milestone set to 7.6.1

The patch looks good, thanks.

Changed 9 months ago by igloo

  • status changed from patch to closed
  • resolution set to wontfix

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.

Changed 9 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.

Changed 9 months ago by jwlato

  • cc jwlato@… added
  • status changed from closed to new
  • resolution wontfix deleted

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.

Changed 8 months ago by igloo

  • status changed from new to closed
  • resolution set to wontfix

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.