    step acc =
      bucketToList >=> \xs -> pure (acc + length xs)

-- | A bucket of weak pointers to different values that all share a hash.
newtype Bucket a
  = Bucket [Weak a] -- Invariant: non-empty list

-- | A singleton bucket.
newBucket :: a -> IO () -> IO (Bucket a)
newBucket =
  bucketAdd (Bucket 
debugSize :: PinBoard a -> IO Int
debugSize (PinBoard boardVar) = do
  board <- readMVar boardVar
  foldlM step 0 board
  where
    step :: Int -> Bucket a -> IO Int
    step acc =
      bucketToList >=> \xs -> pure (acc + length xs)

-- | A bucket of weak pointers to different values that all share a hash.
debugSize (PinBoard boardVar) = do
  board <- readMVar boardVar
  foldlM step 0 board
  where
    step :: Int -> Bucket a -> IO Int
    step acc =
      bucketToList >=> \xs -> pure (acc + length xs)

-- | A bucket of weak pointers to different values that all share a hash.