Reputation: 3606
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?
Upvotes: 6
Views: 145
Reputation: 3606
Simon Meier, the author of this Builder
design, has responded to my question on the bytestring
issue tracker:
The type parameter was there to support the
Put
monad (aWriter
spezialized to fill a buffer during the computation of its value).
Put
is defined as
newtype Put a = Put { unPut :: forall r. (a -> BuildStep r) -> BuildStep r }
and exported from Data.ByteString.Builder.Internal
which is hidden in the current bytestring
release.
Upvotes: 0
Reputation: 152682
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.
Upvotes: 5