Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Possible Changes to Bundle.Chunk?

オープン
#91 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
haskell
領域
data, performance

調査の方向性

Data.Vector.Fusion.Bundle.Monadic から始め、提案されている 3 つの Chunk の設計を、互換性への影響も含めて比較します。この issue では、対象 API、モジュール以外の実装ファイル、テストは特定されていません。まず、順位付けされた選択肢のどれを進めるかについて決定を得てください。選択した Chunk の変更と、提案された utility や instance が、合意された import 先で実装されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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?

主要言語
Haskell
スター
403
フォーク
146
平均マージ
1日 22時間
マージ済み PR(30日)
3

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

haskell/vector のほかの issue

haskell/vector の issue をすべて見る

似ている issue

Haskell の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。