HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulestreamly-0.10.1Haskell2010

Streamly.Data.Array.Foreign

Deprecated. Please use Streamly.Data.Array module from the streamly-core package.

This module provides immutable arrays in pinned memory (non GC memory) suitable for long lived data storage, random access and for interfacing with the operating system.

Arrays in this module are chunks of pinned memory that hold a sequence of Storable values of a given type, they cannot store non-serializable data like functions. Once created an array cannot be modified. Pinned memory allows efficient buffering of long lived data without adding any impact to GC. One array is just one pointer visible to GC and it does not have to be copied across generations. Moreover, pinned memory allows communication with foreign consumers and producers (e.g. file or network IO) without copying the data.

Programmer Notes

Array creation APIs require a MonadIO Monad, except fromList which is a pure API. To operate on streams in pure Monads like Identity you can hoist it to IO monad as follows:

Example4 expressions
import Data.Functor.Identity (Identity, runIdentity)s = Stream.fromList [1..10] :: SerialT Identity Ints1 = Stream.hoist (return . runIdentity) s :: SerialT IO IntStream.fold Array.write s1 :: IO (Array Int)fromList [1,2,3,4,5,6,7,8,9,10]

unsafePerformIO can be used to get a pure API from IO, as long as you know it is safe to do so:

Example2 expressions
import System.IO.Unsafe (unsafePerformIO)unsafePerformIO $ Stream.fold Array.write s1 :: Array IntfromList [1,2,3,4,5,6,7,8,9,10]

To apply a transformation to an array use read to unfold the array into a stream, apply a transformation on the stream and then use write to fold it back to an array.

This module is designed to be imported qualified:

import qualified Streamly.Data.Array as Array

For experimental APIs see Streamly.Internal.Data.Array.

  • 1 type
  • 12 values
  • Packagestreamly-0.10.1
  • Exports13
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceForeign.hs
datadata Array a
#
Instances22NFData1, IsList, Eq, Ord, Read, Show, …
  • NFData1 ArrayDefined in streamly-0.10.1 · Streamly.Data.Array.Foreign · orphan
  • Unbox a => IsList (Array a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Eq (Array Int16)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Eq (Array Int32)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Eq (Array Int64)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Eq (Array Int8)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Eq (Array Word16)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Eq (Array Word32)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Eq (Array Word64)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Eq (Array Word8)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Eq (Array Char)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Eq (Array Int)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • (Unbox a, Eq a) => Eq (Array a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type

    If the type allows a byte-by-byte comparison this instance can be overlapped by a more specific instance that uses byteCmp. Byte comparison can be significantly faster.

  • (Unbox a, Ord a) => Ord (Array a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • (Unbox a, Read a, Show a) => Read (Array a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • (Show a, Unbox a) => Show (Array a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • a ~ Char => IsString (Array a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • Unbox a => Semigroup (Array a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type

    This should not be used for combining many or N arrays as it would copy the two arrays everytime to a new array. For coalescing multiple arrays use fromChunksK instead.

  • Unbox a => Monoid (Array a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type
  • NFData (Array a)Defined in streamly-0.10.1 · Streamly.Data.Array.Foreign · orphan
  • Serialize (Array a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Serialize.Type
  • type Item (Array a) = aDefined in streamly-core-0.2.2 · Streamly.Internal.Data.Array.Type

Arrays

0 declarations

Construction

When performance matters, the fastest way to generate an array is writeN. IsList and IsString instances can be used to conveniently construct arrays from literal values. OverloadedLists extension or fromList can be used to construct an array from a list literal. Similarly, OverloadedStrings extension or fromList can be used to construct an array from a string literal.

valuefromListN :: Unbox a => Int -> [a] -> Array a
#

Create an Array from the first N elements of a list. The array is allocated to size N, if the list terminates before N elements then the array may hold less than N elements.

Elimination

Casting

valuecast :: Unbox b => Array a -> Maybe (Array b)
#

Cast an array having elements of type a into an array having elements of type b. The length of the array should be a multiple of the size of the target element otherwise Nothing is returned.

Random Access

valuelength :: Unbox a => Array a -> Int
#

O(1) Get the length of the array i.e. the number of elements in the array.

Orphan instances

2 instances