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

Modulebasement-0.0.16Haskell2010

Basement.Block

A block of memory that contains elements of a type, very similar to an unboxed array but with the key difference:

  • It doesn't have slicing capability (no cheap take or drop)

  • It consume less memory: 1 Offset, 1 CountOf

  • It's unpackable in any constructor

  • It uses unpinned memory by default

  • 2 types
  • 43 values
  • Packagebasement-0.0.16
  • Exports45
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceBlock.hs
datadata Block ty
#

A block of memory containing unpacked bytes representing values of type ty

Constructors

Instances17IsList, Eq, Data, Ord, Show, Semigroup, …

Properties

1 declaration

Lowlevel functions

8 declarations
valueunsafeFreeze
  1. :: PrimMonad prim
  2. => MutableBlock ty (PrimState prim)
  3. -> prim (Block ty)
#

Freeze a mutable block into a block.

If the mutable block is still use after freeze, then the modification will be reflected in an unexpected way in the Block.

valueunsafeIndex :: PrimType ty => Block ty -> Offset ty -> ty
#

Return the element at a specific index from an array without bounds checking.

Reading from invalid memory can return unpredictable and invalid values. use index if unsure.

valuethaw
  1. :: (PrimMonad prim, PrimType ty)
  2. => Block ty
  3. -> prim (MutableBlock ty (PrimState prim))
#

Thaw a Block into a MutableBlock

the Block is not modified, instead a new Mutable Block is created and its content is copied to the mutable block

valuefreeze
  1. :: (PrimType ty, PrimMonad prim)
  2. => MutableBlock ty (PrimState prim)
  3. -> prim (Block ty)
#

Freeze a MutableBlock into a Block, copying all the data

If the data is modified in the mutable block after this call, then the immutable Block resulting is not impacted.

valueunsafeCast :: PrimType b => Block a -> Block b
#

Unsafely recast an UArray containing a to an UArray containing b

The offset and size are converted from units of a to units of b, but no check are performed to make sure this is compatible.

use cast if unsure.

valuecast :: (PrimType a, PrimType b) => Block a -> Block b
#

Cast a Block of a to a Block of b

The requirement is that the size of type a need to be a multiple or dividend of the size of type b.

If this requirement is not met, the InvalidRecast exception is thrown

safer api

31 declarations
valueempty :: Block ty
#

Create an empty block of memory

valuecreate
  1. :: PrimType ty
  2. => CountOf ty

    the size of the block (in element of ty)

  3. -> (Offset ty -> ty)

    the function that set the value at the index

  4. -> Block ty

    the array created

#

Create a new array of size n by settings each cells through the function f.

valueindex :: PrimType ty => Block ty -> Offset ty -> ty
#

Return the element at a specific index from an array.

If the index @n is out of bounds, an error is raised.

Foreign interfaces

3 declarations
valueunsafeCopyToPtr
  1. :: PrimMonad prim
  2. => Block ty

    the source block to copy

  3. -> Ptr ty

    The destination address where the copy is going to start

  4. -> prim ()
#

Copy all the block content to the memory starting at the destination address

valuewithPtr :: PrimMonad prim => Block ty -> (Ptr ty -> prim a) -> prim a
#

Get a Ptr pointing to the data in the Block.

Since a Block is immutable, this Ptr shouldn't be to use to modify the contents

If the Block is pinned, then its address is returned as is, however if it's unpinned, a pinned copy of the Block is made before getting the address.

Orphan instances

3 instances