Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the type parameter in the bytestring builder internals for?

The core datatypes of Data.ByteString.Builder are

newtype Builder = Builder (forall r. BuildStep r -> BuildStep r)

type BuildStep a = BufferRange -> IO (BuildSignal a)

data BuildSignal a =
    Done {-# UNPACK #-} !(Ptr Word8) a
  | BufferFull
      {-# UNPACK #-} !Int 
      {-# UNPACK #-} !(Ptr Word8)
                     (BuildStep a)
  | InsertChunk
      {-# UNPACK #-} !(Ptr Word8)
                     S.ByteString
                     (BuildStep a)

What purpose does the type parameter (r or a) serve?

like image 660
sjakobi Avatar asked Apr 04 '18 11:04

sjakobi


People also ask

When to use bytestring s?

In short, use bytestring s when your data is processed and stored in bytes. Bytes objects are immutable sequences of single bytes. The documentation has a very good explanation of what they are and how to use them. Ok, so it says "Only ASCII characters are permitted in bytes literals (regardless of the declared source code encoding).

How do I generate large chunks of data from a bytestring?

Create a Builder denoting the same sequence of bytes as a strict ByteString . The Builder inserts large ByteString s directly, but copies small ones to ensure that the generated chunks are large on average. Create a Builder denoting the same sequence of bytes as a lazy ByteString .

How do you make a builder with a strict bytestring?

byteString :: ByteString -> Builder Source #. Create a Builder denoting the same sequence of bytes as a strict ByteString. The Builder inserts large ByteStrings directly, but copies small ones to ensure that the generated chunks are large on average.

What is immutable bytestring?

Immutable sequence of bytes. Provides conversions to and from byte [], String, ByteBuffer, InputStream, OutputStream. Also provides a conversion to CodedInputStream . Like String, the contents of a ByteString can never be observed to change, not even in the presence of a data race or incorrect API usage in the client code.


1 Answers

It is not needed. As proof, I have created a fork which does not change any of the public APIs -- only the API of modules named Internal -- but removes this type argument.

like image 159
Daniel Wagner Avatar answered Oct 26 '22 17:10

Daniel Wagner