buildVector :: CF a => Int -> (Ptr (Ptr (Repr a)) -> IO b) -> IO (V.Vector a, b)
buildVector len f = do
  mvec <- SM.new (fromIntegral len)
  res <- SM.unsafeWith mvec $ \ptr -> f ptr
  vec <- S.unsafeFreeze mvec
  vec' <- V.mapM (get . return) $ S.convert vec
  return (vec', res)
buildVector :: CF a => Int -> (Ptr (Ptr (Repr a)) -> IO b) -> IO (V.Vector a, b)
buildVector len f = do
  mvec <- SM.new (fromIntegral len)
  res <- SM.unsafeWith mvec $ \ptr -> f ptr
  vec <- S.unsafeFreeze mvec
  vec' <- V.mapM (get . return) $ S.convert vec
  return (vec', res)
buildVector len f = do
  mvec <- SM.new (fromIntegral len)
  res <- SM.unsafeWith mvec $ \ptr -> f ptr
  vec <- S.unsafeFreeze mvec
  vec' <- V.mapM (get . return) $ S.convert vec
  return (vec', res)