basement-0.0.15: Foundation scrap box of array & string
License BSD-style
Maintainer Haskell Foundation
Safe Haskell None
Language Haskell2010

Basement.Sized.Block

Description

A Nat-sized version of Block

Synopsis

Documentation

data BlockN (n :: Nat ) a Source #

Sized version of Block

Instances

Instances details
( NatWithinBound ( CountOf ty) n, KnownNat n, PrimType ty) => TryFrom ( Block ty) ( BlockN n ty) Source #
Instance details

Defined in Basement.From

( NatWithinBound ( CountOf ty) n, KnownNat n, PrimType ty) => TryFrom ( UArray ty) ( BlockN n ty) Source #
Instance details

Defined in Basement.From

( NatWithinBound ( CountOf ty) n, KnownNat n, PrimType ty) => TryFrom ( Array ty) ( BlockN n ty) Source #
Instance details

Defined in Basement.From

PrimType a => Eq ( BlockN n a) Source #
Instance details

Defined in Basement.Sized.Block

( KnownNat n, Data a) => Data ( BlockN n a) Source #
Instance details

Defined in Basement.Sized.Block

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> BlockN n a -> c ( BlockN n a) Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( BlockN n a) Source #

toConstr :: BlockN n a -> Constr Source #

dataTypeOf :: BlockN n a -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( BlockN n a)) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( BlockN n a)) Source #

gmapT :: ( forall b. Data b => b -> b) -> BlockN n a -> BlockN n a Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> BlockN n a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> BlockN n a -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> BlockN n a -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> BlockN n a -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> BlockN n a -> m ( BlockN n a) Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> BlockN n a -> m ( BlockN n a) Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> BlockN n a -> m ( BlockN n a) Source #

( PrimType a, Ord a) => Ord ( BlockN n a) Source #
Instance details

Defined in Basement.Sized.Block

( PrimType a, Show a) => Show ( BlockN n a) Source #
Instance details

Defined in Basement.Sized.Block

NormalForm ( BlockN n a) Source #
Instance details

Defined in Basement.Sized.Block

( NatWithinBound Int n, PrimType ty) => From ( BlockN n ty) ( Array ty) Source #
Instance details

Defined in Basement.From

( NatWithinBound Int n, PrimType ty) => From ( BlockN n ty) ( UArray ty) Source #
Instance details

Defined in Basement.From

From ( BlockN n ty) ( Block ty) Source #
Instance details

Defined in Basement.From

( PrimType a, PrimType b, KnownNat n, KnownNat m, ( PrimSize b * m) ~ ( PrimSize a * n)) => From ( BlockN n a) ( BlockN m b) Source #
Instance details

Defined in Basement.From

new :: forall n ty prim. ( PrimType ty, KnownNat n, Countable ty n, PrimMonad prim) => prim ( MutableBlockN n ty ( PrimState prim)) Source #

Create a new unpinned mutable block of a specific N size of ty elements

If the size exceeds a GHC-defined threshold, then the memory will be pinned. To be certain about pinning status with small size, use newPinned

newPinned :: forall n ty prim. ( PrimType ty, KnownNat n, Countable ty n, PrimMonad prim) => prim ( MutableBlockN n ty ( PrimState prim)) Source #

Create a new pinned mutable block of a specific N size of ty elements

index :: forall i n ty. PrimType ty => BlockN n ty -> Offset ty -> ty Source #

foldl' :: PrimType ty => (a -> ty -> a) -> a -> BlockN n ty -> a Source #

foldr :: PrimType ty => (ty -> a -> a) -> a -> BlockN n ty -> a Source #

sub :: forall i j n ty. ((i <=? n) ~ ' True , (j <=? n) ~ ' True , (i <=? j) ~ ' True , PrimType ty, KnownNat i, KnownNat j, Offsetable ty i, Offsetable ty j) => BlockN n ty -> BlockN (j - i) ty Source #

uncons :: forall n ty. ( CmpNat 0 n ~ ' LT , PrimType ty, KnownNat n, Offsetable ty n) => BlockN n ty -> (ty, BlockN (n - 1) ty) Source #

unsnoc :: forall n ty. ( CmpNat 0 n ~ ' LT , KnownNat n, PrimType ty, Offsetable ty n) => BlockN n ty -> ( BlockN (n - 1) ty, ty) Source #

splitAt :: forall i n ty. ( CmpNat i n ~ ' LT , PrimType ty, KnownNat i, Countable ty i) => BlockN n ty -> ( BlockN i ty, BlockN (n - i) ty) Source #

withPtr :: ( PrimMonad prim, KnownNat n) => BlockN n ty -> ( Ptr ty -> prim a) -> prim a Source #

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.

withMutablePtr :: ( PrimMonad prim, KnownNat n) => MutableBlockN n ty ( PrimState prim) -> ( Ptr ty -> prim a) -> prim a Source #

Create a pointer on the beginning of the MutableBlock and call a function f .

The mutable block can be mutated by the f function and the change will be reflected in the mutable block

If the mutable block is unpinned, a trampoline buffer is created and the data is only copied when f return.

it is all-in-all highly inefficient as this cause 2 copies

withMutablePtrHint Source #

Arguments

:: forall n ty prim a. ( PrimMonad prim, KnownNat n)
=> Bool

hint that the buffer doesn't need to have the same value as the mutable block when calling f

-> Bool

hint that the buffer is not supposed to be modified by call of f

-> MutableBlockN n ty ( PrimState prim)
-> ( Ptr ty -> prim a)
-> prim a

Same as withMutablePtr but allow to specify 2 optimisations which is only useful when the MutableBlock is unpinned and need a pinned trampoline to be called safely.

If skipCopy is True, then the first copy which happen before the call to f , is skipped. The Ptr is now effectively pointing to uninitialized data in a new mutable Block.

If skipCopyBack is True, then the second copy which happen after the call to f , is skipped. Then effectively in the case of a trampoline being used the memory changed by f will not be reflected in the original Mutable Block.

If using the wrong parameters, it will lead to difficult to debug issue of corrupted buffer which only present themselves with certain Mutable Block that happened to have been allocated unpinned.

If unsure use withMutablePtr , which default to *not* skip any copy.