HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulestore-0.7.20Haskell2010

Data.Store.Internal

Internal API for the store package. The functions here which are not re-exported by Data.Store are less likely to have stable APIs.

This module also defines most of the included Store instances, for types from the base package and other commonly used packages (bytestring, containers, text, time, etc).

  • 6 types
  • 5 classes
  • 42 values
  • Packagestore-0.7.20
  • Exports53
  • LanguageHaskell2010
  • LicenceMIT
  • SourceInternal.hs

Encoding and decoding strict ByteStrings.

9 declarations
valueencode :: Store a => a -> ByteString
#

Serializes a value to a ByteString. In order to do this, it first allocates a ByteString of the correct size (based on size), and then uses poke to fill it.

Safety of this function depends on correctness of the Store instance. If size returns a. The good news is that this isn't an issue if you use well-tested manual instances (such as those from this package) combined with auomatic definition of instances.

Store class and related types.

4 declarations
classclass Store a where
#

The Store typeclass provides efficient serialization and deserialization to raw pointer addresses.

The peek and poke methods should be defined such that decodeEx (encode x) == x .

Methods

  • size :: Size a

    Yields the Size of the buffer, in bytes, required to store the encoded representation of the type.

    Note that the correctness of this function is crucial for the safety of poke, as it does not do any bounds checking. It is the responsibility of the invoker of poke (encode and similar functions) to ensure that there's enough space in the output buffer. If poke writes beyond, then arbitrary memory can be overwritten, causing undefined behavior and segmentation faults.

  • poke :: a -> Poke ()

    Serializes a value to bytes. It is the responsibility of the caller to ensure that at least the number of bytes required by size are available. These details are handled by encode and similar utilities.

  • peek :: Peek a

    Serialized a value from bytes, throwing exceptions if it encounters invalid data or runs out of input bytes.

Instances310Deriver, Store, …
newtypenewtype Poke a
#

Poke actions are useful for building sequential serializers.

They are actions which write values to bytes into memory specified by a Ptr base. The Applicative and Monad instances make it easy to write serializations, by keeping track of the Offset of the current byte. They allow you to chain Poke action such that subsequent Pokes write into subsequent portions of the output.

Instances5Monad, Functor, MonadFail, Applicative, MonadIO
  • Monad PokeDefined in store-core-0.4.4.7 · Data.Store.Core
  • Functor PokeDefined in store-core-0.4.4.7 · Data.Store.Core
  • MonadFail PokeDefined in store-core-0.4.4.7 · Data.Store.Core
  • Applicative PokeDefined in store-core-0.4.4.7 · Data.Store.Core
  • MonadIO PokeDefined in store-core-0.4.4.7 · Data.Store.Core
newtypenewtype Peek a
#

Peek actions are useful for building sequential deserializers.

They are actions which read from memory and construct values from it. The Applicative and Monad instances make it easy to chain these together to get more complicated deserializers. This machinery keeps track of the current Ptr and end-of-buffer Ptr.

Instances7Monad, Functor, MonadFail, Applicative, MonadIO, PrimMonad, …

Exceptions thrown by Poke

datadata PokeException
#

Exception thrown while running poke. Note that other types of exceptions could also be thrown. Invocations of fail in the Poke monad causes this exception to be thrown.

PokeExceptions are not expected to occur in ordinary circumstances, and usually indicate a programming error.

Instances3Eq, Show, Exception

Exceptions thrown by Peek

datadata PeekException
#

Exception thrown while running peek. Note that other types of exceptions can also be thrown. Invocations of fail in the Poke monad causes this exception to be thrown.

PeekException is thrown when the data being decoded is invalid.

Instances3Eq, Show, Exception

Size type

datadata Size a
#

Info about a type's serialized length. Either the length is known independently of the value, or the length depends on the value.

Constructors

Instances1Contravariant
valuegetSize :: Store a => a -> Int
#

Get the number of bytes needed to store the given value. See size.

valuecombineSize :: (Store a, Store b) => (c -> a) -> (c -> b) -> Size c
#

Create an aggregate Size by providing functions to split the input into two pieces.

If both of the types are ConstSize, the result is ConstSize and the functions will not be used.

valuecombineSizeWith :: (c -> a) -> (c -> b) -> Size a -> Size b -> Size c
#

Create an aggregate Size by providing functions to split the input into two pieces, as well as Size values to use to measure the results.

If both of the input Size values are ConstSize, the result is ConstSize and the functions will not be used.

Store instances in terms of IsSequence

Store instances in terms of IsSet

Store instances in terms of IsMap

Utilities for ordered maps

Store instances in terms of IArray

Store instances in terms of Generic

classclass GStoreSize (f :: Type -> Type) where
#
Instances6GStoreSize
classclass GStorePoke (f :: Type -> Type) where
#
Instances6GStorePoke
classclass GStorePeek (f :: Type -> Type) where
#
Instances6GStorePeek

Peek utilities

valueisolate :: Int -> Peek a -> Peek a
#

Isolate the input to n bytes, skipping n bytes forward. Fails if m advances the offset beyond the isolated region.

Static Size type

newtypenewtype StaticSize (n :: Nat) a
#

Constructors

Instances8Eq, Data, Ord, Show, Generic, NFData, …

Orphan instances

305 instances