[GHC] #7135: Data.Bits can still have default implementations for testBit, bit, and popCount by using -XDefaultSignatures

GHC cvs-ghc at haskell.org
Mon Aug 13 03:28:16 CEST 2012


#7135: Data.Bits can still have default implementations for testBit, bit, and
popCount by using -XDefaultSignatures
------------------------------+---------------------------------------------
 Reporter:  joeyadams         |          Owner:                  
     Type:  feature request   |         Status:  new             
 Priority:  normal            |      Component:  Runtime System  
  Version:                    |       Keywords:                  
       Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
  Failure:  None/Unknown      |       Testcase:                  
Blockedby:                    |       Blocking:                  
  Related:                    |  
------------------------------+---------------------------------------------
 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.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7135>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the Glasgow-haskell-bugs mailing list