primitive-unlifted-2.1.0.0: Primitive GHC types with unlifted types inside
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Primitive.Unlifted.SmallArray

Description

GHC contains three general classes of value types:

  1. Unboxed types: values are machine values made up of fixed numbers of bytes. These include types like Int#, Char# and Addr#.
  2. Unlifted types: values are pointers, but strictly evaluated. These include types like MutVar# s a, Array# a, and MVar# s a.
  3. Lifted types: values are pointers, lazily evaluated.

Certain lifted types are really just thin wrappers around unboxed types (we can call these category 3a) or unlifted pointer types (we can call these category 3b) Category 3a includes Int, Char, and `Ptr a`, while category 3b includes IORef a, Data.Primitive.Array.Array a, and MVar a.

Types in category 3a can be stored efficiently in a Data.Primitive.PrimArray.PrimArray, removing and applying wrappers as required. This module provides the same facility for types in category 3b.

Synopsis

Types

data SmallUnliftedArray_ a unlifted_a Source #

A SmallUnliftedArray_ a unlifted_a represents an array of values of a lifted type a that wrap values of an unlifted type unlifted_a. It is expected that unlifted_a ~ Unlifted a, but imposing that constraint here would force the type roles to nominal, which is often undesirable when arrays are used as components of larger datatypes.

Constructors

SmallUnliftedArray (SmallUnliftedArray# unlifted_a) 

Instances

Instances details
(PrimUnlifted a, unlifted_a ~ Unlifted a) => Monoid (SmallUnliftedArray_ a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

Methods

mempty :: SmallUnliftedArray_ a unlifted_a #

mappend :: SmallUnliftedArray_ a unlifted_a -> SmallUnliftedArray_ a unlifted_a -> SmallUnliftedArray_ a unlifted_a #

mconcat :: [SmallUnliftedArray_ a unlifted_a] -> SmallUnliftedArray_ a unlifted_a #

(PrimUnlifted a, unlifted_a ~ Unlifted a) => Semigroup (SmallUnliftedArray_ a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

Methods

(<>) :: SmallUnliftedArray_ a unlifted_a -> SmallUnliftedArray_ a unlifted_a -> SmallUnliftedArray_ a unlifted_a #

sconcat :: NonEmpty (SmallUnliftedArray_ a unlifted_a) -> SmallUnliftedArray_ a unlifted_a #

stimes :: Integral b => b -> SmallUnliftedArray_ a unlifted_a -> SmallUnliftedArray_ a unlifted_a #

(PrimUnlifted a, unlifted_a ~ Unlifted a) => IsList (SmallUnliftedArray_ a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

Associated Types

type Item (SmallUnliftedArray_ a unlifted_a) #

Methods

fromList :: [Item (SmallUnliftedArray_ a unlifted_a)] -> SmallUnliftedArray_ a unlifted_a #

fromListN :: Int -> [Item (SmallUnliftedArray_ a unlifted_a)] -> SmallUnliftedArray_ a unlifted_a #

toList :: SmallUnliftedArray_ a unlifted_a -> [Item (SmallUnliftedArray_ a unlifted_a)] #

(Show a, PrimUnlifted a, unlifted_a ~ Unlifted a) => Show (SmallUnliftedArray_ a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

Methods

showsPrec :: Int -> SmallUnliftedArray_ a unlifted_a -> ShowS #

show :: SmallUnliftedArray_ a unlifted_a -> String #

showList :: [SmallUnliftedArray_ a unlifted_a] -> ShowS #

(Eq a, PrimUnlifted a, unlifted_a ~ Unlifted a) => Eq (SmallUnliftedArray_ a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

Methods

(==) :: SmallUnliftedArray_ a unlifted_a -> SmallUnliftedArray_ a unlifted_a -> Bool #

(/=) :: SmallUnliftedArray_ a unlifted_a -> SmallUnliftedArray_ a unlifted_a -> Bool #

unlifted_a ~ Unlifted a => PrimUnlifted (SmallUnliftedArray_ a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

Associated Types

type Unlifted (SmallUnliftedArray_ a unlifted_a) :: UnliftedType Source #

type Item (SmallUnliftedArray_ a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

type Item (SmallUnliftedArray_ a unlifted_a) = a
type Unlifted (SmallUnliftedArray_ a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

type Unlifted (SmallUnliftedArray_ a unlifted_a) = SmallUnliftedArray# unlifted_a

type SmallUnliftedArray a = SmallUnliftedArray_ a (Unlifted a) Source #

A type synonym for a SmallUnliftedArray_ containing lifted values of a particular type. As a general rule, this type synonym should not be used in class instances—use SmallUnliftedArray_ with an equality constraint instead. It also should not be used when defining newtypes or datatypes, unless those will have restrictive type roles regardless—use SmallUnliftedArray_ instead.

data SmallMutableUnliftedArray_ s a unlifted_a Source #

Instances

Instances details
unlifted_a ~ Unlifted a => Eq (SmallMutableUnliftedArray_ s a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

Methods

(==) :: SmallMutableUnliftedArray_ s a unlifted_a -> SmallMutableUnliftedArray_ s a unlifted_a -> Bool #

(/=) :: SmallMutableUnliftedArray_ s a unlifted_a -> SmallMutableUnliftedArray_ s a unlifted_a -> Bool #

unlifted_a ~ Unlifted a => PrimUnlifted (SmallMutableUnliftedArray_ s a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

Associated Types

type Unlifted (SmallMutableUnliftedArray_ s a unlifted_a) :: UnliftedType Source #

type Unlifted (SmallMutableUnliftedArray_ s a unlifted_a) Source # 
Instance details

Defined in Data.Primitive.Unlifted.SmallArray.ST

Operations

newSmallUnliftedArray Source #

Arguments

:: (PrimMonad m, PrimUnlifted a) 
=> Int

size

-> a

initial value

-> m (SmallMutableUnliftedArray (PrimState m) a) 

Creates a new MutableUnliftedArray with the specified value as initial contents.

unsafeNewSmallUnliftedArray Source #

Arguments

:: PrimMonad m 
=> Int

size

-> m (SmallMutableUnliftedArray (PrimState m) a) 

Creates a new MutableUnliftedArray. This function is unsafe because it initializes all elements of the array as pointers to the empty array. Attempting to read one of these elements before writing to it is in effect an unsafe coercion from UnliftedArray a to the element type.

sizeofSmallUnliftedArray :: SmallUnliftedArray e -> Int Source #

Yields the length of an UnliftedArray.

getSizeofSmallMutableUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> m Int Source #

Yields the length of a MutableUnliftedArray.

sameSmallMutableUnliftedArray :: SmallMutableUnliftedArray s a -> SmallMutableUnliftedArray s a -> Bool Source #

Determines whether two MutableUnliftedArray values are the same. This is object/pointer identity, not based on the contents.

unsafeFreezeSmallUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> m (SmallUnliftedArray a) Source #

Freezes a MutableUnliftedArray, yielding an UnliftedArray. This simply marks the array as frozen in place, so it should only be used when no further modifications to the mutable array will be performed.

freezeSmallUnliftedArray Source #

Arguments

:: PrimMonad m 
=> SmallMutableUnliftedArray (PrimState m) a

source

-> Int

offset

-> Int

length

-> m (SmallUnliftedArray a) 

Freezes a portion of a SmallMutableUnliftedArray, yielding a SmallUnliftedArray. This operation is safe, in that it copies the frozen portion, and the existing mutable array may still be used afterward.

thawSmallUnliftedArray Source #

Arguments

:: PrimMonad m 
=> SmallUnliftedArray a

source

-> Int

offset

-> Int

length

-> m (SmallMutableUnliftedArray (PrimState m) a) 

Thaws a portion of a SmallUnliftedArray, yielding a SmallMutableUnliftedArray. This copies the thawed portion, so mutations will not affect the original array.

unsafeThawSmallUnliftedArray Source #

Arguments

:: PrimMonad m 
=> SmallUnliftedArray a

source

-> m (SmallMutableUnliftedArray (PrimState m) a) 

Thaw a SmallUnliftedArray, yielding a SmallMutableUnliftedArray. This does not make a copy.

setSmallUnliftedArray Source #

Arguments

:: (PrimMonad m, PrimUnlifted a) 
=> SmallMutableUnliftedArray (PrimState m) a

destination

-> a

value to fill with

-> Int

offset

-> Int

length

-> m () 

copySmallUnliftedArray Source #

Arguments

:: PrimMonad m 
=> SmallMutableUnliftedArray (PrimState m) a

destination

-> Int

offset into destination

-> SmallUnliftedArray a

source

-> Int

offset into source

-> Int

number of elements to copy

-> m () 

Copies the contents of an immutable array into a mutable array.

copySmallMutableUnliftedArray Source #

Arguments

:: PrimMonad m 
=> SmallMutableUnliftedArray (PrimState m) a

destination

-> Int

offset into destination

-> SmallMutableUnliftedArray (PrimState m) a

source

-> Int

offset into source

-> Int

number of elements to copy

-> m () 

Copies the contents of one mutable array into another.

cloneSmallUnliftedArray Source #

Arguments

:: SmallUnliftedArray a

source

-> Int

offset

-> Int

length

-> SmallUnliftedArray a 

Creates a copy of a portion of a SmallUnliftedArray_

cloneSmallMutableUnliftedArray Source #

Arguments

:: PrimMonad m 
=> SmallMutableUnliftedArray (PrimState m) a

source

-> Int

offset

-> Int

length

-> m (SmallMutableUnliftedArray (PrimState m) a) 

Creates a new MutableUnliftedArray containing a copy of a portion of another mutable array.

runSmallUnliftedArray :: (forall s. ST s (SmallMutableUnliftedArray s a)) -> SmallUnliftedArray a Source #

Execute a stateful computation and freeze the resulting array.

dupableRunSmallUnliftedArray :: (forall s. ST s (SmallMutableUnliftedArray s a)) -> SmallUnliftedArray a Source #

Execute a stateful computation and freeze the resulting array. It is possible, but unlikely, that the computation will be run multiple times in multiple threads.

List Conversion

smallUnliftedArrayToList :: PrimUnlifted a => SmallUnliftedArray a -> [a] Source #

Convert the unlifted array to a list.

Folding

foldrSmallUnliftedArray :: forall a b. PrimUnlifted a => (a -> b -> b) -> b -> SmallUnliftedArray a -> b Source #

foldrSmallUnliftedArray' :: forall a b. PrimUnlifted a => (a -> b -> b) -> b -> SmallUnliftedArray a -> b Source #

Strict right-associated fold over the elements of an 'SmallUnliftedArray.

foldlSmallUnliftedArray :: forall a b. PrimUnlifted a => (b -> a -> b) -> b -> SmallUnliftedArray a -> b Source #

Lazy left-associated fold over the elements of an SmallUnliftedArray_.

foldlSmallUnliftedArray' :: forall a b. PrimUnlifted a => (b -> a -> b) -> b -> SmallUnliftedArray a -> b Source #

Strict left-associated fold over the elements of an SmallUnliftedArray_.

foldlSmallUnliftedArrayM' :: (PrimUnlifted a, Monad m) => (b -> a -> m b) -> b -> SmallUnliftedArray a -> m b Source #

Strict effectful left-associated fold over the elements of an SmallUnliftedArray_.

Traversals

traverseSmallUnliftedArray_ :: (PrimUnlifted a, Applicative m) => (a -> m b) -> SmallUnliftedArray a -> m () Source #

Effectfully traverse the elements of an SmallUnliftedArray_, discarding the resulting values.

itraverseSmallUnliftedArray_ :: (PrimUnlifted a, Applicative m) => (Int -> a -> m b) -> SmallUnliftedArray a -> m () Source #

Effectful indexed traversal of the elements of an SmallUnliftedArray_, discarding the resulting values.

Mapping