Skip to content

Commit d703a17

Browse files
committed
Added a silly 'fromList/toList' rule and made bit set size lazy
1 parent 20c9040 commit d703a17

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Data/BitSet/Generic.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ import qualified Data.List as List
9393

9494
-- | A bit set with unspecified container type.
9595
data GBitSet c a = (Enum a, Bits c, Num c) => BitSet
96-
{ _n :: {-# UNPACK #-} !Int -- ^ Number of elements in the bit set.
96+
{ _n :: Int -- ^ Number of elements in the bit set.
9797
#if defined(__GLASGOW_HASKELL__) && (__GLASGOW_HASKELL__ >= 708)
9898
, _bits :: {-# UNPACK #-} !c -- ^ Bit container.
9999
#else
@@ -263,13 +263,16 @@ filter f = fromList . List.filter f . toList
263263
-- | /O(d * n)/. Convert this bit set set to a list of elements.
264264
toList :: Num c => GBitSet c a -> [a]
265265
toList bs = build (\k z -> foldr k z bs)
266-
{-# INLINE toList #-}
266+
{-# INLINE [0] toList #-}
267267

268268
-- | /O(d * n)/. Make a bit set from a list of elements.
269269
fromList :: (Enum a, Bits c, Num c) => [a] -> GBitSet c a
270270
fromList xs = BitSet { _n = popCount b, _bits = b } where
271271
b = List.foldl' (\i x -> i `setBit` fromEnum x) 0 xs
272-
{-# INLINE fromList #-}
272+
{-# INLINE [0] fromList #-}
273+
{-# RULES
274+
"fromList/toList" forall bs. fromList (toList bs) = bs
275+
#-}
273276

274277
-- | /O(1)/. Internal function, which extracts the underlying container
275278
-- from the bit set.

0 commit comments

Comments
 (0)