HORIZON HASKELLDocslts/ghc-10.0.x2b276322026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 2b27632 · 2026-10-31

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

Contents
  1. Properties
  2. Lowlevel functions
  3. safer api
  4. Foreign interfaces
Synopsis
  • 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

Lowlevel functions

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.

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

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

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