HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulererebase-1.21.2Haskell2010

Data.ByteString.Builder.Prim.Internal

  • 3 types
  • 21 values
  • Packagererebase-1.21.2
  • Exports24
  • LanguageHaskell2010
  • LicenceMIT
  • SourceInternal.hs
value(>$<) :: Contravariant f => (b -> a) -> f a -> f b
#

A fmap-like operator for builder primitives, both bounded and fixed size.

Builder primitives are contravariant so it's like the normal fmap, but backwards (look at the type). (If it helps to remember, the operator symbol is like ($) but backwards.)

We can use it for example to prepend and/or append fixed values to an primitive.

 import Data.ByteString.Builder.Prim as P
showEncoding ((\x -> ('\'', (x, '\''))) >$< fixed3) 'x' = "'x'"
  where
    fixed3 = P.char7 >*< P.char7 >*< P.char7

Note that the rather verbose syntax for composition stems from the requirement to be able to compute the size / size bound at compile time.

typetype Size = Int
#

The type used for sizes and sizeBounds of sizes.

datadata BoundedPrim a
#

A builder primitive that always results in sequence of bytes that is no longer than a pre-determined bound.

Instances2Contravariant, Monoidal
  • Contravariant BoundedPrimDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.Prim.Internal
  • Monoidal BoundedPrimDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.Prim.Internal
value(>*<) :: Monoidal f => f a -> f b -> f (a, b)
#

A pairing/concatenation operator for builder primitives, both bounded and fixed size.

For example,

toLazyByteString (primFixed (char7 >*< char7) ('x','y')) = "xy"

We can combine multiple primitives using >*< multiple times.

toLazyByteString (primFixed (char7 >*< char7 >*< char7) ('x',('y','z'))) = "xyz"
datadata FixedPrim a
#

A builder primitive that always results in a sequence of bytes of a pre-determined, fixed size.

Instances2Contravariant, Monoidal
  • Contravariant FixedPrimDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.Prim.Internal
  • Monoidal FixedPrimDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.Prim.Internal
valuecaseWordSize_32_64 :: a -> a -> a
#

Select an implementation depending on bitness. Throw a compile time error if bitness is neither 32 nor 64.

valuestorableToF :: Storable a => FixedPrim a
#

Deprecated. Deprecated since bytestring-0.12.1.0.This function is dangerous in the presence of internal padding and makes naive assumptions about alignment.

  • For a primitive Haskell type like Int64, use the corresponding primitive like int64Host.

  • For other types, it is recommended to manually write a small function that performs the necessary unaligned write and zeroes or removes any internal padding bits.