Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Possible Changes to Bundle.Chunk?

Đang mở
#91 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
haskell
Lĩnh vực
data, performance

Hướng nghiên cứu

Bắt đầu với Data.Vector.Fusion.Bundle.Monadic và so sánh ba thiết kế Chunk được đề xuất, bao gồm các ảnh hưởng của chúng đối với khả năng tương thích. Issue không xác định API đích, tệp triển khai nào ngoài module, hoặc các bài kiểm thử. Trước tiên, hãy đạt được quyết định về việc theo đuổi tùy chọn nào trong các tùy chọn được xếp hạng; được xem là hoàn tất khi thay đổi Chunk được chọn và mọi utility hoặc instance được đề xuất đã được triển khai với vị trí import được thống nhất.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

design-shed enhancement question

As it is, the Chunk type in Data.Vector.Fusion.Bundle.Monadic is much less useful than it could be.Here are some ways, ranked by desirability and compatibility-breaking, on how it could be better.

  1. Add a Monoid instance and utility functions for Chunk.
    This is the simplest change, and one that breaks the fewest programs. The most general utility functions would probably be toChunk :: (Vector v a) => v a -> Chunk v a and fromChunk :: (Vector v a) => Chunk v a -> v a, and possibly singleton :: (Vector v a) => a -> Chunk v a. This would let Chunks be used like ByteString Builders, as a low-overhead, O(1) concatenation option.

The definition for Monoid would be:

import qualified Data.Vector.Generic.Mutable as M
instance Monoid (Chunk v a) where
    mempty = Chunk 0 (const $ return ())
    mappend (Chunk na wa) (Chunk nb wb) = Chunk (na + nb) (\v -> wa (M.take na v) >> wb (M.drop na v))
  1. Change the type of Chunk.
    This would involve a Yoneda transform on Chunk's type:
data Chunk v a = Chunk Int (forall m r. (PrimMonad m, Vector v r) => Mutable v (PrimState m) r -> (a -> r) -> m ())

This would turn Chunk into a Functor, meaning the Functor instance for Bundle could be a lot simpler and involve a lot less copying. Also, this prevents badly-behaved Chunks from reading and mutating the MVector they are given.

  1. Change the kind of Chunk.
    If you generalize, then you can make Chunks that can construct any type of Vector:
data Chunk a = Chunk Int (forall m v r. (PrimMonad m, Vector v r) => Mutable v (PrimState m) r -> (a -> r) -> m ())

In addition to making Chunks able to produce any kind of Vector, this also admits an Applicative instance for Chunk!

import qualified Data.Vector.Generic.Mutable as M
import qualified Data.Vector.Mutable as MV
instance Applicative Chunk where
    pure a = Chunk 1 (\v c -> M.write v 0 (c a))
    (Chunk nf wf) <*> (Chunk na wa) = Chunk (nf * na) $ \v c -> do
        vf <- MV.new nf
        wf vf id
        let loop n = if n >= nf then return () else do
            f <- MV.read vf n
            wa (M.slice (n * na) na v) (c . f)
            loop (n + 1)
        loop 0
    (Chunk na _) *> (Chunk nb wb) = Chunk (na * nb) $ \v c -> do
        let loop n = if n >= na then return () else wb (M.slice (n * nb) nb) c >> loop (n + 1)
        loop 0

This also makes it an Alternative, with empty and <|> defined as mempty and mappend, respectively.

If these changes are made, then it would probably be a good idea to move Chunk from its current location and give it a dedicated import, like Data.Vector.Chunk, for use in building Vectors cheaply.

So is it possible to make these changes and make Chunk more than just a utility type for Bundle?

Ngôn ngữ chính
Haskell
Star
403
Fork
146
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của haskell/vector

Tất cả issue của haskell/vector

Issue tương tự

Thêm issue về Haskell

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.