### Haskell Mutable Vector Read/Write Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Mutable Demonstrates how to generate a mutable vector, read elements safely using `readMaybe`, and handle out-of-bounds access. ```Haskell import qualified Data.Vector.Mutable as MV v <- MV.generate 10 (\x -> x*x) MV.readMaybe v 3 MV.readMaybe v 13 ``` -------------------------------- ### Generate Vector Bundle from Step and Count Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Fusion-Bundle Generates a vector bundle starting from a value, with a given step, for a specified number of elements. ```Haskell enumFromStepN :: forall a (v :: Type -> Type). Num a => a -> a -> Int -> Bundle v a ``` -------------------------------- ### Example: Reading an element from a mutable vector (Haskell) Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic-Mutable Demonstrates how to generate a mutable vector and read an element from a specific index using `MV.read`. ```Haskell import qualified Data.Vector.Strict.Mutable as MV v <- MV.generate 10 (\x -> x*x) MV.read v 3 ``` -------------------------------- ### Haskell Unboxed Vector Instance for Product Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Details the instance for `Vector (Product a)` in the `Data.Vector.Unboxed.Base` module. It includes methods for freezing, thawing, slicing, indexing, copying, and sequence checking, requiring `Unbox a`. ```Haskell basicUnsafeFreeze :: Mutable Vector s (Product a) -> ST s (Vector (Product a)) basicUnsafeThaw :: Vector (Product a) -> ST s (Mutable Vector s (Product a)) basicLength :: Vector (Product a) -> Int basicUnsafeSlice :: Int -> Int -> Vector (Product a) -> Vector (Product a) basicUnsafeIndexM :: Vector (Product a) -> Int -> Box (Product a) basicUnsafeCopy :: Mutable Vector s (Product a) -> Vector (Product a) -> ST s () elemseq :: Vector (Product a) -> Product a -> b -> b ``` -------------------------------- ### Haskell: Create Vector with unfoldrExactN Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Strict Explains `unfoldrExactN` for creating a vector with an exact number of elements using a generator function and a seed. The example creates a vector of exactly three descending integers starting from 10. ```Haskell unfoldrExactN 3 (\n -> (n,n-1)) 10 = <10,9,8> ``` -------------------------------- ### Haskell Unboxed Vector Instance for Min Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Details the instance for `Vector (Min a)` in the `Data.Vector.Unboxed.Base` module. It includes methods for freezing, thawing, slicing, indexing, copying, and sequence checking, requiring `Unbox a`. ```Haskell basicUnsafeFreeze :: Mutable Vector s (Min a) -> ST s (Vector (Min a)) basicUnsafeThaw :: Vector (Min a) -> ST s (Mutable Vector s (Min a)) basicLength :: Vector (Min a) -> Int basicUnsafeSlice :: Int -> Int -> Vector (Min a) -> Vector (Min a) basicUnsafeIndexM :: Vector (Min a) -> Int -> Box (Min a) basicUnsafeCopy :: Mutable Vector s (Min a) -> Vector (Min a) -> ST s () elemseq :: Vector (Min a) -> Min a -> b -> b ``` -------------------------------- ### Haskell: Create Vector with unfoldrN Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Strict Demonstrates `unfoldrN` for creating a vector with a maximum number of elements using a generator function and a seed. The example creates a vector of the first three descending integers starting from 10. ```Haskell unfoldrN 3 (\n -> Just (n,n-1)) 10 = <10,9,8> ``` -------------------------------- ### Vector Initialization and Replication Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Unboxed-Mutable This snippet demonstrates how to create new mutable vectors. It includes functions for creating vectors of a specific size, replicating elements, and generating vectors based on a function, all within a `PrimMonad` context. ```Haskell new :: (PrimMonad m, Unbox a) => Int -> m (MVector (PrimState m) a) unsafeNew :: (PrimMonad m, Unbox a) => Int -> m (MVector (PrimState m) a) replicate :: (PrimMonad m, Unbox a) => Int -> a -> m (MVector (PrimState m) a) replicateM :: (PrimMonad m, Unbox a) => Int -> m a -> m (MVector (PrimState m) a) generate :: (PrimMonad m, Unbox a) => Int -> (Int -> a) -> m (MVector (PrimState m) a) generateM :: (PrimMonad m, Unbox a) => Int -> (Int -> m a) -> m (MVector (PrimState m) a) ``` -------------------------------- ### IterateN Example in Haskell Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Storable An example demonstrating the usage of `iterateN` to generate a vector by repeatedly applying a function. ```Haskell import qualified Data.Vector.Storable as VS -- Example 1: Empty vector VS.iterateN 0 undefined undefined :: VS.Vector Int -- Example 2: Generating a string using succ VS.iterateN 26 succ 'a' ``` -------------------------------- ### Vector Initialization in Haskell Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Storable Demonstrates methods for creating vectors, including empty, singleton, replicating elements, generating elements with a function, and iterating a function. ```Haskell empty :: Storable a => Vector a singleton :: Storable a => a -> Vector a replicate :: Storable a => Int -> a -> Vector a generate :: Storable a => Int -> (Int -> a) -> Vector a iterateN :: Storable a => Int -> (a -> a) -> a -> Vector a ``` -------------------------------- ### Haskell: Get Size and Alignment of Down a Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Provides functions to get the size and alignment of the Down a type, where 'a' is a primitive type. ```Haskell sizeOfType# :: Proxy (Down a) -> Int# #sizeOf# :: Down a -> Int# #alignmentOfType# :: Proxy (Down a) -> Int# #alignment# :: Down a -> Int# ``` -------------------------------- ### Haskell: Get Size and Alignment of Down a Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive-Mutable Provides functions to get the size and alignment of the Down a type, where 'a' is a primitive type. ```Haskell sizeOfType# :: Proxy (Down a) -> Int# #sizeOf# :: Down a -> Int# #alignmentOfType# :: Proxy (Down a) -> Int# #alignment# :: Down a -> Int# ``` -------------------------------- ### Haskell Vector minimumOn Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Shows how to find the minimum element in a Haskell vector based on a key extracted by a function using `minimumOn`. Ties are resolved by choosing the first element. ```Haskell import qualified Data.Vector.Strict as V V.minimumOn fst $ V.fromList [(2,'a'), (1,'b')] ``` ```Haskell import qualified Data.Vector.Strict as V V.minimumOn fst $ V.fromList [(1,'a'), (1,'b')] ``` -------------------------------- ### Enumerate Vector from Start Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Yields a vector of a given length, containing values starting from `x` and incrementing by 1. ```Haskell enumFromN :: (Vector v a, Num a) => a -> Int -> v a enumFromN 5 3 = <5,6,7> ``` -------------------------------- ### Haskell Unboxed Vector Instance for Dual Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Details the instance for `Vector (Dual a)` in the `Data.Vector.Unboxed.Base` module. It includes methods for freezing, thawing, slicing, indexing, copying, and sequence checking, requiring `Unbox a`. ```Haskell basicUnsafeFreeze :: Mutable Vector s (Dual a) -> ST s (Vector (Dual a)) basicUnsafeThaw :: Vector (Dual a) -> ST s (Mutable Vector s (Dual a)) basicLength :: Vector (Dual a) -> Int basicUnsafeSlice :: Int -> Int -> Vector (Dual a) -> Vector (Dual a) basicUnsafeIndexM :: Vector (Dual a) -> Int -> Box (Dual a) basicUnsafeCopy :: Mutable Vector s (Dual a) -> Vector (Dual a) -> ST s () elemseq :: Vector (Dual a) -> Dual a -> b -> b ``` -------------------------------- ### Haskell: Get Size and Alignment of First a Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Provides functions to get the size and alignment of the First a type, where 'a' is a primitive type. ```Haskell sizeOfType# :: Proxy (First a) -> Int# #sizeOf# :: First a -> Int# #alignmentOfType# :: Proxy (First a) -> Int# #alignment# :: First a -> Int# ``` -------------------------------- ### Haskell: Get Size and Alignment of Identity a Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Provides functions to get the size and alignment of the Identity a type, where 'a' is a primitive type. ```Haskell sizeOfType# :: Proxy (Identity a) -> Int# #sizeOf# :: Identity a -> Int# #alignmentOfType# :: Proxy (Identity a) -> Int# #alignment# :: Identity a -> Int# ``` -------------------------------- ### Show Instance for Vector (Haskell) Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Provides a 'Show' instance for 'Vector', allowing vectors to be converted to strings for display. This includes functions for precise string representation. ```Haskell instance (Show a, Prim a) => Show (Vector a) where showsPrec :: Int -> Vector a -> ShowS show :: Vector a -> String showList :: [Vector a] -> ShowS ``` -------------------------------- ### Haskell: Examples for fromListN Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Demonstrates the usage of `fromListN` to convert a specified number of elements from a list into a vector. Shows behavior with lists longer and shorter than the specified count. ```Haskell import qualified Data.Vector.Strict as V V.fromListN 3 [1,2,3,4,5] V.fromListN 3 [1] ``` -------------------------------- ### Haskell: Get Size and Alignment of Complex a Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Provides functions to get the size and alignment of the Complex a type, where 'a' is a primitive type. ```Haskell sizeOfType# :: Proxy (Complex a) -> Int# #sizeOf# :: Complex a -> Int# #alignmentOfType# :: Proxy (Complex a) -> Int# #alignment# :: Complex a -> Int# ``` -------------------------------- ### Haskell: Initializing Mutable Vectors Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Storable-Mutable Demonstrates methods for creating and initializing mutable vectors. Includes functions for creating new, replicated, and generated vectors. ```Haskell new :: (PrimMonad m, Storable a) => Int -> m (MVector (PrimState m) a) unsafeNew :: (PrimMonad m, Storable a) => Int -> m (MVector (PrimState m) a) replicate :: (PrimMonad m, Storable a) => Int -> a -> m (MVector (PrimState m) a) replicateM :: (PrimMonad m, Storable a) => Int -> m a -> m (MVector (PrimState m) a) generate :: (PrimMonad m, Storable a) => Int -> (Int -> a) -> m (MVector (PrimState m) a) generateM :: (PrimMonad m, Storable a) => Int -> (Int -> m a) -> m (MVector (PrimState m) a) ``` -------------------------------- ### Haskell: Get Size and Alignment of First a Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive-Mutable Provides functions to get the size and alignment of the First a type, where 'a' is a primitive type. ```Haskell sizeOfType# :: Proxy (First a) -> Int# #sizeOf# :: First a -> Int# #alignmentOfType# :: Proxy (First a) -> Int# #alignment# :: First a -> Int# ``` -------------------------------- ### Haskell: Get Size and Alignment of Identity a Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive-Mutable Provides functions to get the size and alignment of the Identity a type, where 'a' is a primitive type. ```Haskell sizeOfType# :: Proxy (Identity a) -> Int# #sizeOf# :: Identity a -> Int# #alignmentOfType# :: Proxy (Identity a) -> Int# #alignment# :: Identity a -> Int# ``` -------------------------------- ### Haskell Vector minimum Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Illustrates finding the minimum element in a Haskell vector using the `minimum` function. It handles ties by returning the first occurrence and supports custom ordering with `Data.Semigroup.Arg`. ```Haskell import qualified Data.Vector.Strict as V V.minimum $ V.fromList [2, 1] ``` ```Haskell import Data.Semigroup V.minimum $ V.fromList [Arg 2 'a', Arg 1 'b'] ``` ```Haskell import Data.Semigroup V.minimum $ V.fromList [Arg 1 'a', Arg 1 'b'] ``` -------------------------------- ### Haskell: Get Size and Alignment of Complex a Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive-Mutable Provides functions to get the size and alignment of the Complex a type, where 'a' is a primitive type. ```Haskell sizeOfType# :: Proxy (Complex a) -> Int# #sizeOf# :: Complex a -> Int# #alignmentOfType# :: Proxy (Complex a) -> Int# #alignment# :: Complex a -> Int# ``` -------------------------------- ### Haskell: Slicing and Sub-vector Operations with Data.Vector.Generic.New Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic-New Illustrates functions for creating sub-vectors or modified views of the `New` vector initializations, such as `slice`, `init`, `tail`, `take`, and `drop`. It also includes unsafe variants for performance-critical scenarios. ```Haskell slice :: forall (v :: Type -> Type) a. Vector v a => Int -> Int -> New v a -> New v a Source init :: forall (v :: Type -> Type) a. Vector v a => New v a -> New v a Source tail :: forall (v :: Type -> Type) a. Vector v a => New v a -> New v a Source take :: forall (v :: Type -> Type) a. Vector v a => Int -> New v a -> New v a Source drop :: forall (v :: Type -> Type) a. Vector v a => Int -> New v a -> New v a Source unsafeSlice :: forall (v :: Type -> Type) a. Vector v a => Int -> Int -> New v a -> New v a Source unsafeInit :: forall (v :: Type -> Type) a. Vector v a => New v a -> New v a Source unsafeTail :: forall (v :: Type -> Type) a. Vector v a => New v a -> New v a Source ``` -------------------------------- ### Enumerate Vector from Start Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Storable Yields a vector of a given length, containing sequential values starting from 'x'. More efficient than enumFromTo. ```Haskell enumFromN :: (Storable a, Num a) => a -> Int -> Vector a enumFromN 5 3 = <5,6,7> ``` -------------------------------- ### MVector Any Instance Methods Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic-Mutable-Base Provides the instance details for mutable unboxed vectors of Any type. It includes methods for length, slicing, overlap checking, creation, initialization, replication, reading, writing, clearing, setting, copying, moving, and growing. ```Haskell basicLength :: MVector s Any -> Int basicUnsafeSlice :: Int -> Int -> MVector s Any -> MVector s Any basicOverlaps :: MVector s Any -> MVector s Any -> Bool basicUnsafeNew :: Int -> ST s (MVector s Any) basicInitialize :: MVector s Any -> ST s () basicUnsafeReplicate :: Int -> Any -> ST s (MVector s Any) basicUnsafeRead :: MVector s Any -> Int -> ST s Any basicUnsafeWrite :: MVector s Any -> Int -> Any -> ST s () basicClear :: MVector s Any -> ST s () basicSet :: MVector s Any -> Any -> ST s () basicUnsafeCopy :: MVector s Any -> MVector s Any -> ST s () basicUnsafeMove :: MVector s Any -> MVector s Any -> ST s () basicUnsafeGrow :: MVector s Any -> Int -> ST s (MVector s Any) ``` -------------------------------- ### Haskell: Enumerate Vector from Start Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Yields a vector of a given length, containing sequential values starting from 'x'. More efficient than `enumFromTo`. ```Haskell enumFromN :: (Prim a, Num a) => a -> Int -> Vector a enumFromN 5 3 = <5,6,7> ``` -------------------------------- ### Vector Show Instance Methods Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Storable Defines how vectors are converted to string representations. `showsPrec` is used for showing vectors with precedence, and `show` and `showList` provide standard string conversions. ```Haskell showsPrec :: Int -> Vector a -> ShowS show :: Vector a -> String showList :: [Vector a] -> ShowS ``` -------------------------------- ### Haskell: Read Vector Element Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Mutable Demonstrates reading an element from a mutable vector created using `generate`. It shows how to access a specific element by its index. ```Haskell import qualified Data.Vector.Mutable as MV v <- MV.generate 10 (x -> x*x) MV.read v 3 -- Expected output: 9 ``` -------------------------------- ### Monadic Stream Indexing Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Fusion-Stream-Monadic Adds an index to each element of a monadic stream. 'indexed' starts from 0, while 'indexedR' allows specifying a starting index. ```Haskell indexed :: forall (m :: Type -> Type) a. Monad m => Stream m a -> Stream m (Int, a) indexedR :: forall (m :: Type -> Type) a. Monad m => Int -> Stream m a -> Stream m (Int, a) ``` -------------------------------- ### Monad Instance for Box Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Fusion-Stream-Monadic Outlines the Monad instance for the Box type, including (>>=), (>>), and return. These methods enable sequential computation and binding within the Box context. ```Haskell (>>=) :: Box a -> (a -> Box b) -> Box b (>>) :: Box a -> Box b -> Box b return :: a -> Box a ``` -------------------------------- ### Haskell iterateN Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Example usage of the 'iterateN' function to generate a vector of characters by repeatedly applying the 'succ' function to an initial character. ```Haskell import qualified Data.Vector.Primitive as VP VP.iterateN 26 succ 'a' ``` -------------------------------- ### Haskell Unboxed Vector Instance for DoNotUnboxLazy Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Details the instance for `Vector (DoNotUnboxLazy a)` in the `Data.Vector.Unboxed.Base` module. It includes methods for freezing, thawing, slicing, indexing, copying, and sequence checking. ```Haskell basicUnsafeFreeze :: Mutable Vector s (DoNotUnboxLazy a) -> ST s (Vector (DoNotUnboxLazy a)) basicUnsafeThaw :: Vector (DoNotUnboxLazy a) -> ST s (Mutable Vector s (DoNotUnboxLazy a)) basicLength :: Vector (DoNotUnboxLazy a) -> Int basicUnsafeSlice :: Int -> Int -> Vector (DoNotUnboxLazy a) -> Vector (DoNotUnboxLazy a) basicUnsafeIndexM :: Vector (DoNotUnboxLazy a) -> Int -> Box (DoNotUnboxLazy a) basicUnsafeCopy :: Mutable Vector s (DoNotUnboxLazy a) -> Vector (DoNotUnboxLazy a) -> ST s () elemseq :: Vector (DoNotUnboxLazy a) -> DoNotUnboxLazy a -> b -> b ``` -------------------------------- ### Haskell: Get Size and Alignment of Word Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Provides functions to get the size and alignment of the Word type using `sizeOfType#`, `sizeOf#`, `alignmentOfType#`, and `alignment#`. ```Haskell sizeOfType# :: Proxy Word -> Int# #sizeOf# :: Word -> Int# #alignmentOfType# :: Proxy Word -> Int# #alignment# :: Word -> Int# ``` -------------------------------- ### Haskell: Bundle Construction Functions Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Fusion-Bundle Provides functions for constructing `Bundle`s: `singleton` creates a bundle with a single element, `cons` adds an element to the beginning, `snoc` adds an element to the end, `replicate` creates a bundle with repeated elements, and `generate` creates a bundle by applying a function to indices. ```Haskell singleton :: forall a (v :: Type -> Type). a -> Bundle v a ``` ```Haskell cons :: forall a (v :: Type -> Type). a -> Bundle v a -> Bundle v a ``` ```Haskell snoc :: forall (v :: Type -> Type) a. Bundle v a -> a -> Bundle v a ``` ```Haskell replicate :: forall a (v :: Type -> Type). Int -> a -> Bundle v a ``` ```Haskell generate :: forall a (v :: Type -> Type). Int -> (Int -> a) -> Bundle v a ``` -------------------------------- ### Haskell: Get Size and Alignment of Int Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Provides functions to get the size and alignment of the Int type using `sizeOfType#`, `sizeOf#`, `alignmentOfType#`, and `alignment#`. ```Haskell sizeOfType# :: Proxy Int -> Int# #sizeOf# :: Int -> Int# #alignmentOfType# :: Proxy Int -> Int# #alignment# :: Int -> Int# ``` -------------------------------- ### Haskell: Get Size and Alignment of Float Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Provides functions to get the size and alignment of the Float type using `sizeOfType#`, `sizeOf#`, `alignmentOfType#`, and `alignment#`. ```Haskell sizeOfType# :: Proxy Float -> Int# #sizeOf# :: Float -> Int# #alignmentOfType# :: Proxy Float -> Int# #alignment# :: Float -> Int# ``` -------------------------------- ### MVector Int64 Instance Methods Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic-Mutable-Base Provides the instance details for mutable unboxed vectors of Int64. It includes methods for length, slicing, overlap checking, creation, initialization, replication, reading, writing, clearing, setting, copying, moving, and growing. ```Haskell basicLength :: MVector s Int64 -> Int basicUnsafeSlice :: Int -> Int -> MVector s Int64 -> MVector s Int64 basicOverlaps :: MVector s Int64 -> MVector s Int64 -> Bool basicUnsafeNew :: Int -> ST s (MVector s Int64) basicInitialize :: MVector s Int64 -> ST s () basicUnsafeReplicate :: Int -> Int64 -> ST s (MVector s Int64) basicUnsafeRead :: MVector s Int64 -> Int -> ST s Int64 basicUnsafeWrite :: MVector s Int64 -> Int -> Int64 -> ST s () basicClear :: MVector s Int64 -> ST s () basicSet :: MVector s Int64 -> Int64 -> ST s () basicUnsafeCopy :: MVector s Int64 -> MVector s Int64 -> ST s () basicUnsafeMove :: MVector s Int64 -> MVector s Int64 -> ST s () basicUnsafeGrow :: MVector s Int64 -> Int -> ST s (MVector s Int64) ``` -------------------------------- ### Haskell: Get Size and Alignment of Word Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive-Mutable Provides functions to get the size and alignment of the Word type using `sizeOfType#`, `sizeOf#`, `alignmentOfType#`, and `alignment#`. ```Haskell sizeOfType# :: Proxy Word -> Int# #sizeOf# :: Word -> Int# #alignmentOfType# :: Proxy Word -> Int# #alignment# :: Word -> Int# ``` -------------------------------- ### Bundle Construction Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Fusion-Bundle-Monadic Provides functions for creating `Bundle`s: `empty` for an empty bundle, `singleton` for a single element, `cons` to prepend, `snoc` to append, `replicate` to repeat a value, `replicateM` for monadic repetition, and `generate`/`generateM` for creating bundles from indices. ```Haskell empty :: forall (m :: Type -> Type) (v :: Type -> Type) a. Monad m => Bundle m v a Source # Empty `Bundle` singleton :: forall (m :: Type -> Type) a (v :: Type -> Type). Monad m => a -> Bundle m v a Source # Singleton `Bundle` cons :: forall (m :: Type -> Type) a (v :: Type -> Type). Monad m => a -> Bundle m v a -> Bundle m v a Source # Prepend an element snoc :: forall (m :: Type -> Type) (v :: Type -> Type) a. Monad m => Bundle m v a -> a -> Bundle m v a Source # Append an element replicate :: forall (m :: Type -> Type) a (v :: Type -> Type). Monad m => Int -> a -> Bundle m v a Source # Replicate a value to a given length replicateM :: forall m a (v :: Type -> Type). Monad m => Int -> m a -> Bundle m v a Source # Yield a `Bundle` of values obtained by performing the monadic action the given number of times generate :: forall (m :: Type -> Type) a (v :: Type -> Type). Monad m => Int -> (Int -> a) -> Bundle m v a Source # generateM :: forall m a (v :: Type -> Type). Monad m => Int -> (Int -> m a) -> Bundle m v a Source # Generate a stream from its indices ``` -------------------------------- ### Haskell: Get Size and Alignment of Int Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive-Mutable Provides functions to get the size and alignment of the Int type using `sizeOfType#`, `sizeOf#`, `alignmentOfType#`, and `alignment#`. ```Haskell sizeOfType# :: Proxy Int -> Int# #sizeOf# :: Int -> Int# #alignmentOfType# :: Proxy Int -> Int# #alignment# :: Int -> Int# ``` -------------------------------- ### Haskell Monadic Bundle Construction and Conversion Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Fusion-Bundle-Monadic Provides functions to create and convert monadic bundles. Includes lifting bundles to different monads, creating empty or singleton bundles, replicating elements, and generating bundles from functions. ```Haskell lift :: forall (m :: Type -> Type) (v :: Type -> Type) a. Monad m => Bundle Id v a -> Bundle m v a empty :: forall (m :: Type -> Type) (v :: Type -> Type) a. Monad m => Bundle m v a singleton :: forall (m :: Type -> Type) a (v :: Type -> Type). Monad m => a -> Bundle m v a cons :: forall (m :: Type -> Type) a (v :: Type -> Type). Monad m => a -> Bundle m v a -> Bundle m v a snoc :: forall (m :: Type -> Type) (v :: Type -> Type) a. Monad m => Bundle m v a -> a -> Bundle m v a replicate :: forall (m :: Type -> Type) a (v :: Type -> Type). Monad m => Int -> a -> Bundle m v a replicateM :: forall m a (v :: Type -> Type). Monad m => Int -> m a -> Bundle m v a generate :: forall (m :: Type -> Type) a (v :: Type -> Type). Monad m => Int -> (Int -> a) -> Bundle m v a generateM :: forall m a (v :: Type -> Type). Monad m => Int -> (Int -> m a) -> Bundle m v a unbox :: forall (m :: Type -> Type) (v :: Type -> Type) a. Monad m => Bundle m v (Box a) -> Bundle m v a ``` -------------------------------- ### Haskell Vector maximumOn Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Shows how to find the maximum element in a Haskell vector based on a key extracted by a function using `maximumOn`. Ties are resolved by choosing the first element. ```Haskell import qualified Data.Vector.Strict as V V.maximumOn fst $ V.fromList [(2,'a'), (1,'b')] ``` ```Haskell import qualified Data.Vector.Strict as V V.maximumOn fst $ V.fromList [(1,'a'), (1,'b')] ``` -------------------------------- ### Haskell: Get Size and Alignment of Float Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive-Mutable Provides functions to get the size and alignment of the Float type using `sizeOfType#`, `sizeOf#`, `alignmentOfType#`, and `alignment#`. ```Haskell sizeOfType# :: Proxy Float -> Int# #sizeOf# :: Float -> Int# #alignmentOfType# :: Proxy Float -> Int# #alignment# :: Float -> Int# ``` -------------------------------- ### Generate Vector Bundle from Start to End Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Fusion-Bundle Generates a vector bundle with elements from a start value to an end value, inclusive, using the `Enum` instance. ```Haskell enumFromTo :: forall a (v :: Type -> Type). Enum a => a -> a -> Bundle v a ``` -------------------------------- ### Haskell MVector Unboxed Instance for Word64 Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic-Mutable Provides the MVector instance for Word64 in Haskell's vector package. It includes methods for basic operations like getting the length, slicing, checking for overlaps, creating new vectors, initializing, replicating, reading, writing, clearing, setting, copying, moving, and growing unboxed mutable vectors of Word64. ```Haskell basicLength :: MVector s Word64 -> Int basicUnsafeSlice :: Int -> Int -> MVector s Word64 -> MVector s Word64 basicOverlaps :: MVector s Word64 -> MVector s Word64 -> Bool basicUnsafeNew :: Int -> ST s (MVector s Word64) basicInitialize :: MVector s Word64 -> ST s () basicUnsafeReplicate :: Int -> Word64 -> ST s (MVector s Word64) basicUnsafeRead :: MVector s Word64 -> Int -> ST s Word64 basicUnsafeWrite :: MVector s Word64 -> Int -> Word64 -> ST s () basicClear :: MVector s Word64 -> ST s () basicSet :: MVector s Word64 -> Word64 -> ST s () basicUnsafeCopy :: MVector s Word64 -> MVector s Word64 -> ST s () basicUnsafeMove :: MVector s Word64 -> MVector s Word64 -> ST s () basicUnsafeGrow :: MVector s Word64 -> Int -> ST s (MVector s Word64) ``` -------------------------------- ### Haskell Storable Vector Identity Check (isSameVector) Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Storable Provides an example of checking if two Storable vectors are the same, meaning they share the same buffer and have the same length. The example uses a vector of Doubles. ```Haskell import qualified Data.Vector.Storable as VS let xs = VS.fromList [0/0::Double] in VS.isSameVector xs xs ``` -------------------------------- ### Unboxed Vector First Instance Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Defines the instance for unboxed vectors of First a, where 'a' must be an instance of Unbox. It includes methods for freezing, thawing, getting the length, slicing, indexing, copying, and sequential element checking. ```Haskell basicUnsafeFreeze :: Mutable Vector s (First a) -> ST s (Vector (First a)) Source # basicUnsafeThaw :: Vector (First a) -> ST s (Mutable Vector s (First a)) Source # basicLength :: Vector (First a) -> Int Source # basicUnsafeSlice :: Int -> Int -> Vector (First a) -> Vector (First a) Source # basicUnsafeIndexM :: Vector (First a) -> Int -> Box (First a) Source # basicUnsafeCopy :: Mutable Vector s (First a) -> Vector (First a) -> ST s () Source # elemseq :: Vector (First a) -> First a -> b -> b Source # ``` -------------------------------- ### Haskell Vector minimumBy Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Demonstrates finding the minimum element in a Haskell vector using a custom comparison function with `minimumBy`. Ties are resolved by selecting the first occurrence. ```Haskell import Data.Ord import qualified Data.Vector.Strict as V V.minimumBy (comparing fst) $ V.fromList [(2,'a'), (1,'b')] ``` ```Haskell import Data.Ord import qualified Data.Vector.Strict as V V.minimumBy (comparing fst) $ V.fromList [(1,'a'), (1,'b')] ``` -------------------------------- ### Haskell Vector scanl Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector Provides an example of V.scanl, a left-to-right scan that includes the initial value and all subsequent accumulated results. This snippet uses addition for accumulation. ```Haskell import qualified Data.Vector as V V.scanl (+) 0 (V.fromList [1,2,3,4]) ``` -------------------------------- ### Haskell: Get Size and Alignment of CSUSeconds Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Provides functions to get the size and alignment of the CSUSeconds type using proxy and direct methods. These are essential for memory layout calculations. ```Haskell sizeOfType# :: Proxy CSUSeconds -> Int# #sizeOf# :: CSUSeconds -> Int# #alignmentOfType# :: Proxy CSUSeconds -> Int# #alignment# :: CSUSeconds -> Int# ``` -------------------------------- ### Haskell Vector Construction Functions Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Details functions for creating new vectors, including empty, singleton, replicating elements, generating elements from a function, and iterating a function. ```Haskell empty :: Vector v a => v a -- The empty vector. singleton :: Vector v a => a -> v a -- A vector with exactly one element. replicate :: Vector v a => Int -> a -> v a -- A vector of the given length with the same value in each position. generate :: Vector v a => Int -> (Int -> a) -> v a -- Construct a vector of the given length by applying the function to each index. iterateN :: Vector v a => Int -> (a -> a) -> a -> v a -- Apply the function max(n-1,0) times to an initial value, producing a vector of length max(n,0). -- The 0th element will contain the initial value, which is why there is one less function application than the number of elements in the produced vector. ``` -------------------------------- ### Haskell: Get Size and Alignment of CSUSeconds Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive-Mutable Provides functions to get the size and alignment of the CSUSeconds type using proxy and direct methods. These are essential for memory layout calculations. ```Haskell sizeOfType# :: Proxy CSUSeconds -> Int# #sizeOf# :: CSUSeconds -> Int# #alignmentOfType# :: Proxy CSUSeconds -> Int# #alignment# :: CSUSeconds -> Int# ``` -------------------------------- ### MVector Int32 Instance Methods Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic-Mutable-Base Provides the instance details for mutable unboxed vectors of Int32. It includes methods for length, slicing, overlap checking, creation, initialization, replication, reading, writing, clearing, setting, copying, moving, and growing. ```Haskell basicLength :: MVector s Int32 -> Int basicUnsafeSlice :: Int -> Int -> MVector s Int32 -> MVector s Int32 basicOverlaps :: MVector s Int32 -> MVector s Int32 -> Bool basicUnsafeNew :: Int -> ST s (MVector s Int32) basicInitialize :: MVector s Int32 -> ST s () basicUnsafeReplicate :: Int -> Int32 -> ST s (MVector s Int32) basicUnsafeRead :: MVector s Int32 -> Int -> ST s Int32 basicUnsafeWrite :: MVector s Int32 -> Int -> Int32 -> ST s () basicClear :: MVector s Int32 -> ST s () basicSet :: MVector s Int32 -> Int32 -> ST s () basicUnsafeCopy :: MVector s Int32 -> MVector s Int32 -> ST s () basicUnsafeMove :: MVector s Int32 -> MVector s Int32 -> ST s () basicUnsafeGrow :: MVector s Int32 -> Int -> ST s (MVector s Int32) ``` -------------------------------- ### Haskell Vector Recycling Support Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Provides utilities for creating new vectors from monadic initializers and converting existing vectors into initializers for cloning. ```Haskell new :: Vector v a => New v a -> v a Construct a vector from a monadic initialiser. clone :: Vector v a => v a -> New v a Convert a vector to an initialiser which, when run, produces a copy of the vector. ``` -------------------------------- ### Haskell Vector Product Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Strict Illustrates how to compute the product of elements in a Haskell Vector using `V.product`. Examples include a non-empty vector and an empty vector. ```Haskell import qualified Data.Vector as V V.product $ V.fromList [1,2,3,4] V.product (V.empty :: V.Vector Int) ``` -------------------------------- ### Haskell Vector postscanl Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector Shows how to use V.postscanl for a left-to-right scan, returning all intermediate scans except the initial value. The example demonstrates accumulation using addition. ```Haskell import qualified Data.Vector as V V.postscanl (+) 0 (V.fromList [1,2,3,4]) ``` -------------------------------- ### Haskell Monadic Vector Initialization Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Primitive Functions for initializing vectors using monadic actions, allowing for effects during vector creation. Includes functions for replicating, generating, and iterating with monadic actions. ```Haskell replicateM :: (Monad m, Prim a) => Int -> m a -> m (Vector a) generateM :: (Monad m, Prim a) => Int -> (Int -> m a) -> m (Vector a) iterateNM :: (Monad m, Prim a) => Int -> (a -> m a) -> a -> m (Vector a) ``` -------------------------------- ### Haskell MVector Unboxed Instance for Word64 Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic-Mutable-Base Provides the MVector instance for Word64 in Haskell's vector package. It includes methods for basic operations like getting the length, slicing, checking for overlaps, creating new vectors, initializing, replicating, reading, writing, clearing, setting, copying, moving, and growing unboxed mutable vectors of Word64. ```Haskell basicLength :: MVector s Word64 -> Int basicUnsafeSlice :: Int -> Int -> MVector s Word64 -> MVector s Word64 basicOverlaps :: MVector s Word64 -> MVector s Word64 -> Bool basicUnsafeNew :: Int -> ST s (MVector s Word64) basicInitialize :: MVector s Word64 -> ST s () basicUnsafeReplicate :: Int -> Word64 -> ST s (MVector s Word64) basicUnsafeRead :: MVector s Word64 -> Int -> ST s Word64 basicUnsafeWrite :: MVector s Word64 -> Int -> Word64 -> ST s () basicClear :: MVector s Word64 -> ST s () basicSet :: MVector s Word64 -> Word64 -> ST s () basicUnsafeCopy :: MVector s Word64 -> MVector s Word64 -> ST s () basicUnsafeMove :: MVector s Word64 -> MVector s Word64 -> ST s () basicUnsafeGrow :: MVector s Word64 -> Int -> ST s (MVector s Word64) ``` -------------------------------- ### Haskell Vector scanr1 min/max Examples Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Strict Provides examples for `scanr1` in Haskell, illustrating its use with minimum and maximum functions on a vector. It includes cases for non-empty and empty vectors. ```Haskell import qualified Data.Vector as V V.scanr1 min $ V.fromListN 5 [3,1,4,2,4] V.scanr1 max $ V.fromListN 5 [4,5,2,3,1] V.scanr1 min (V.empty :: V.Vector Int) ``` -------------------------------- ### Haskell Unboxed Vector Instance for Sum Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Generic Details the instance for `Vector (Sum a)` in the `Data.Vector.Unboxed.Base` module. It includes methods for freezing, thawing, slicing, indexing, copying, and sequence checking, requiring `Unbox a`. ```Haskell basicUnsafeFreeze :: Mutable Vector s (Sum a) -> ST s (Vector (Sum a)) basicUnsafeThaw :: Vector (Sum a) -> ST s (Mutable Vector s (Sum a)) basicLength :: Vector (Sum a) -> Int basicUnsafeSlice :: Int -> Int -> Vector (Sum a) -> Vector (Sum a) basicUnsafeIndexM :: Vector (Sum a) -> Int -> Box (Sum a) basicUnsafeCopy :: Mutable Vector s (Sum a) -> Vector (Sum a) -> ST s () elemseq :: Vector (Sum a) -> Sum a -> b -> b ``` -------------------------------- ### Haskell Vector MinimumOn Example Source: https://hackage.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Strict Illustrates finding the minimum element in a Haskell Vector by applying a key function using `V.minimumOn`. Examples use `fst` to compare tuples. ```Haskell import qualified Data.Vector as V V.minimumOn fst $ V.fromList [(2,'a'), (1,'b')] V.minimumOn fst $ V.fromList [(1,'a'), (1,'b')] ```