Commit 276c4621 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Derive `FiniteBits` for integral newtype wrappers



When `FiniteBits` was introduced in cddc9024e67a6d4c01bb190839d0134af8c907e0
only the standard Haskell 2010 finite-size integral types were given a
`FiniteBits` instance, however, since also a DEPRECATION warning was put
in place (as per 701d9ed4b2bec5922709a91bfb625881d7dd47f0) for `bitSize`
which might point people to to `FiniteBits`, it seems sensible to derive
`FiniteBits` for all integral newtype wrappers as well.

N.B.: This makes `Integer` the only type in `base` with a `Bits`
      instance but no `FiniteBits` instance.
Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
parent cc4ba35f
......@@ -74,7 +74,7 @@ module Foreign.C.Types
) where
import Foreign.Storable
import Data.Bits ( Bits(..) )
import Data.Bits ( Bits(..), FiniteBits(..) )
import Data.Int ( Int8, Int16, Int32, Int64 )
import Data.Word ( Word8, Word16, Word32, Word64 )
import Data.Typeable
......
......@@ -39,7 +39,7 @@ available = False
#include <sys/epoll.h>
import Control.Monad (when)
import Data.Bits (Bits, (.|.), (.&.))
import Data.Bits (Bits, FiniteBits, (.|.), (.&.))
import Data.Maybe (Maybe(..))
import Data.Monoid (Monoid(..))
import Data.Word (Word32)
......@@ -163,7 +163,7 @@ newtype ControlOp = ControlOp CInt
newtype EventType = EventType {
unEventType :: Word32
} deriving (Show, Eq, Num, Bits)
} deriving (Show, Eq, Num, Bits, FiniteBits)
#{enum EventType, EventType
, epollIn = EPOLLIN
......
......@@ -27,7 +27,7 @@ available = False
#else
import Control.Monad (when)
import Data.Bits (Bits(..))
import Data.Bits (Bits(..), FiniteBits(..))
import Data.Maybe (Maybe(..))
import Data.Monoid (Monoid(..))
import Data.Word (Word16, Word32)
......@@ -180,7 +180,7 @@ newtype Flag = Flag Word32
#else
newtype Flag = Flag Word16
#endif
deriving (Bits, Eq, Num, Show, Storable)
deriving (Bits, FiniteBits, Eq, Num, Show, Storable)
#{enum Flag, Flag
, flagAdd = EV_ADD
......@@ -193,7 +193,7 @@ newtype Filter = Filter Word32
#else
newtype Filter = Filter Word16
#endif
deriving (Bits, Eq, Num, Show, Storable)
deriving (Bits, FiniteBits, Eq, Num, Show, Storable)
filterRead :: Filter
filterRead = Filter (#const EVFILT_READ)
......
......@@ -26,7 +26,7 @@ available = False
import Control.Concurrent.MVar (MVar, newMVar, swapMVar)
import Control.Monad ((=<<), liftM, liftM2, unless)
import Data.Bits (Bits, (.|.), (.&.))
import Data.Bits (Bits, FiniteBits, (.|.), (.&.))
import Data.Maybe (Maybe(..))
import Data.Monoid (Monoid(..))
import Data.Word
......@@ -150,7 +150,7 @@ data PollFd = PollFd {
} deriving (Show)
newtype Event = Event CShort
deriving (Eq, Show, Num, Storable, Bits)
deriving (Eq, Show, Num, Storable, Bits, FiniteBits)
-- We have to duplicate the whole enum like this in order for the
-- hsc2hs cross-compilation mode to work
......
......@@ -17,7 +17,7 @@
-- // GHC can derive any class for a newtype, so we make use of that here...
#define ARITHMETIC_CLASSES Eq,Ord,Num,Enum,Storable,Real,Typeable
#define INTEGRAL_CLASSES Bounded,Integral,Bits
#define INTEGRAL_CLASSES Bounded,Integral,Bits,FiniteBits
#define FLOATING_CLASSES Fractional,Floating,RealFrac,RealFloat
#define ARITHMETIC_TYPE(T,B) \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment