Movatterモバイル変換


[0]ホーム

URL:


array-0.5.4.0: Mutable and immutable arrays
Copyright(c) The University of Glasgow 2001
LicenseBSD-style (see the file libraries/base/LICENSE)
Maintainerlibraries@haskell.org
Stabilityexperimental
Portabilitynon-portable (uses Data.Array.Base)
Safe HaskellTrustworthy
LanguageHaskell2010

Data.Array.IArray

Contents

Description

Immutable arrays, with an overloaded interface. For array types which can be used with this interface, see theArray type exported by this module and theData.Array.Unboxed module. Other packages, such as diffarray, also provide arrays using this interface.

Synopsis

Array classes

classIArray a eSource#

Class of immutable array types.

An array type has the form(a i e) wherea is the array typeconstructor (kind* -> * -> *),i is the index type (a member ofthe classIx), ande is the element type. TheIArray class isparameterised over botha ande, so that instances specialised tocertain element types can be defined.

Minimal complete definition

bounds, numElements, unsafeArray, unsafeAt

Instances

Instances details
IArrayArray eSource# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>Array i e -> (i, i)Source#

numElements ::Ix i =>Array i e ->Int

unsafeArray ::Ix i => (i, i) -> [(Int, e)] ->Array i e

unsafeAt ::Ix i =>Array i e ->Int -> e

unsafeReplace ::Ix i =>Array i e -> [(Int, e)] ->Array i e

unsafeAccum ::Ix i => (e -> e' -> e) ->Array i e -> [(Int, e')] ->Array i e

unsafeAccumArray ::Ix i => (e -> e' -> e) -> e -> (i, i) -> [(Int, e')] ->Array i e

IArrayUArrayBoolSource# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iBool -> (i, i)Source#

numElements ::Ix i =>UArray iBool ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Bool)] ->UArray iBool

unsafeAt ::Ix i =>UArray iBool ->Int ->Bool

unsafeReplace ::Ix i =>UArray iBool -> [(Int,Bool)] ->UArray iBool

unsafeAccum ::Ix i => (Bool -> e' ->Bool) ->UArray iBool -> [(Int, e')] ->UArray iBool

unsafeAccumArray ::Ix i => (Bool -> e' ->Bool) ->Bool -> (i, i) -> [(Int, e')] ->UArray iBool

IArrayUArrayCharSource# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iChar -> (i, i)Source#

numElements ::Ix i =>UArray iChar ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Char)] ->UArray iChar

unsafeAt ::Ix i =>UArray iChar ->Int ->Char

unsafeReplace ::Ix i =>UArray iChar -> [(Int,Char)] ->UArray iChar

unsafeAccum ::Ix i => (Char -> e' ->Char) ->UArray iChar -> [(Int, e')] ->UArray iChar

unsafeAccumArray ::Ix i => (Char -> e' ->Char) ->Char -> (i, i) -> [(Int, e')] ->UArray iChar

IArrayUArrayDoubleSource# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iDouble -> (i, i)Source#

numElements ::Ix i =>UArray iDouble ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Double)] ->UArray iDouble

unsafeAt ::Ix i =>UArray iDouble ->Int ->Double

unsafeReplace ::Ix i =>UArray iDouble -> [(Int,Double)] ->UArray iDouble

unsafeAccum ::Ix i => (Double -> e' ->Double) ->UArray iDouble -> [(Int, e')] ->UArray iDouble

unsafeAccumArray ::Ix i => (Double -> e' ->Double) ->Double -> (i, i) -> [(Int, e')] ->UArray iDouble

IArrayUArrayFloatSource# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iFloat -> (i, i)Source#

numElements ::Ix i =>UArray iFloat ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Float)] ->UArray iFloat

unsafeAt ::Ix i =>UArray iFloat ->Int ->Float

unsafeReplace ::Ix i =>UArray iFloat -> [(Int,Float)] ->UArray iFloat

unsafeAccum ::Ix i => (Float -> e' ->Float) ->UArray iFloat -> [(Int, e')] ->UArray iFloat

unsafeAccumArray ::Ix i => (Float -> e' ->Float) ->Float -> (i, i) -> [(Int, e')] ->UArray iFloat

IArrayUArrayIntSource# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iInt -> (i, i)Source#

numElements ::Ix i =>UArray iInt ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Int)] ->UArray iInt

unsafeAt ::Ix i =>UArray iInt ->Int ->Int

unsafeReplace ::Ix i =>UArray iInt -> [(Int,Int)] ->UArray iInt

unsafeAccum ::Ix i => (Int -> e' ->Int) ->UArray iInt -> [(Int, e')] ->UArray iInt

unsafeAccumArray ::Ix i => (Int -> e' ->Int) ->Int -> (i, i) -> [(Int, e')] ->UArray iInt

IArrayUArrayInt8Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iInt8 -> (i, i)Source#

numElements ::Ix i =>UArray iInt8 ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Int8)] ->UArray iInt8

unsafeAt ::Ix i =>UArray iInt8 ->Int ->Int8

unsafeReplace ::Ix i =>UArray iInt8 -> [(Int,Int8)] ->UArray iInt8

unsafeAccum ::Ix i => (Int8 -> e' ->Int8) ->UArray iInt8 -> [(Int, e')] ->UArray iInt8

unsafeAccumArray ::Ix i => (Int8 -> e' ->Int8) ->Int8 -> (i, i) -> [(Int, e')] ->UArray iInt8

IArrayUArrayInt16Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iInt16 -> (i, i)Source#

numElements ::Ix i =>UArray iInt16 ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Int16)] ->UArray iInt16

unsafeAt ::Ix i =>UArray iInt16 ->Int ->Int16

unsafeReplace ::Ix i =>UArray iInt16 -> [(Int,Int16)] ->UArray iInt16

unsafeAccum ::Ix i => (Int16 -> e' ->Int16) ->UArray iInt16 -> [(Int, e')] ->UArray iInt16

unsafeAccumArray ::Ix i => (Int16 -> e' ->Int16) ->Int16 -> (i, i) -> [(Int, e')] ->UArray iInt16

IArrayUArrayInt32Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iInt32 -> (i, i)Source#

numElements ::Ix i =>UArray iInt32 ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Int32)] ->UArray iInt32

unsafeAt ::Ix i =>UArray iInt32 ->Int ->Int32

unsafeReplace ::Ix i =>UArray iInt32 -> [(Int,Int32)] ->UArray iInt32

unsafeAccum ::Ix i => (Int32 -> e' ->Int32) ->UArray iInt32 -> [(Int, e')] ->UArray iInt32

unsafeAccumArray ::Ix i => (Int32 -> e' ->Int32) ->Int32 -> (i, i) -> [(Int, e')] ->UArray iInt32

IArrayUArrayInt64Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iInt64 -> (i, i)Source#

numElements ::Ix i =>UArray iInt64 ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Int64)] ->UArray iInt64

unsafeAt ::Ix i =>UArray iInt64 ->Int ->Int64

unsafeReplace ::Ix i =>UArray iInt64 -> [(Int,Int64)] ->UArray iInt64

unsafeAccum ::Ix i => (Int64 -> e' ->Int64) ->UArray iInt64 -> [(Int, e')] ->UArray iInt64

unsafeAccumArray ::Ix i => (Int64 -> e' ->Int64) ->Int64 -> (i, i) -> [(Int, e')] ->UArray iInt64

IArrayUArrayWordSource# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iWord -> (i, i)Source#

numElements ::Ix i =>UArray iWord ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Word)] ->UArray iWord

unsafeAt ::Ix i =>UArray iWord ->Int ->Word

unsafeReplace ::Ix i =>UArray iWord -> [(Int,Word)] ->UArray iWord

unsafeAccum ::Ix i => (Word -> e' ->Word) ->UArray iWord -> [(Int, e')] ->UArray iWord

unsafeAccumArray ::Ix i => (Word -> e' ->Word) ->Word -> (i, i) -> [(Int, e')] ->UArray iWord

IArrayUArrayWord8Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iWord8 -> (i, i)Source#

numElements ::Ix i =>UArray iWord8 ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Word8)] ->UArray iWord8

unsafeAt ::Ix i =>UArray iWord8 ->Int ->Word8

unsafeReplace ::Ix i =>UArray iWord8 -> [(Int,Word8)] ->UArray iWord8

unsafeAccum ::Ix i => (Word8 -> e' ->Word8) ->UArray iWord8 -> [(Int, e')] ->UArray iWord8

unsafeAccumArray ::Ix i => (Word8 -> e' ->Word8) ->Word8 -> (i, i) -> [(Int, e')] ->UArray iWord8

IArrayUArrayWord16Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iWord16 -> (i, i)Source#

numElements ::Ix i =>UArray iWord16 ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Word16)] ->UArray iWord16

unsafeAt ::Ix i =>UArray iWord16 ->Int ->Word16

unsafeReplace ::Ix i =>UArray iWord16 -> [(Int,Word16)] ->UArray iWord16

unsafeAccum ::Ix i => (Word16 -> e' ->Word16) ->UArray iWord16 -> [(Int, e')] ->UArray iWord16

unsafeAccumArray ::Ix i => (Word16 -> e' ->Word16) ->Word16 -> (i, i) -> [(Int, e')] ->UArray iWord16

IArrayUArrayWord32Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iWord32 -> (i, i)Source#

numElements ::Ix i =>UArray iWord32 ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Word32)] ->UArray iWord32

unsafeAt ::Ix i =>UArray iWord32 ->Int ->Word32

unsafeReplace ::Ix i =>UArray iWord32 -> [(Int,Word32)] ->UArray iWord32

unsafeAccum ::Ix i => (Word32 -> e' ->Word32) ->UArray iWord32 -> [(Int, e')] ->UArray iWord32

unsafeAccumArray ::Ix i => (Word32 -> e' ->Word32) ->Word32 -> (i, i) -> [(Int, e')] ->UArray iWord32

IArrayUArrayWord64Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray iWord64 -> (i, i)Source#

numElements ::Ix i =>UArray iWord64 ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Word64)] ->UArray iWord64

unsafeAt ::Ix i =>UArray iWord64 ->Int ->Word64

unsafeReplace ::Ix i =>UArray iWord64 -> [(Int,Word64)] ->UArray iWord64

unsafeAccum ::Ix i => (Word64 -> e' ->Word64) ->UArray iWord64 -> [(Int, e')] ->UArray iWord64

unsafeAccumArray ::Ix i => (Word64 -> e' ->Word64) ->Word64 -> (i, i) -> [(Int, e')] ->UArray iWord64

IArrayUArray (StablePtr a)Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray i (StablePtr a) -> (i, i)Source#

numElements ::Ix i =>UArray i (StablePtr a) ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,StablePtr a)] ->UArray i (StablePtr a)

unsafeAt ::Ix i =>UArray i (StablePtr a) ->Int ->StablePtr a

unsafeReplace ::Ix i =>UArray i (StablePtr a) -> [(Int,StablePtr a)] ->UArray i (StablePtr a)

unsafeAccum ::Ix i => (StablePtr a -> e' ->StablePtr a) ->UArray i (StablePtr a) -> [(Int, e')] ->UArray i (StablePtr a)

unsafeAccumArray ::Ix i => (StablePtr a -> e' ->StablePtr a) ->StablePtr a -> (i, i) -> [(Int, e')] ->UArray i (StablePtr a)

IArrayUArray (Ptr a)Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray i (Ptr a) -> (i, i)Source#

numElements ::Ix i =>UArray i (Ptr a) ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,Ptr a)] ->UArray i (Ptr a)

unsafeAt ::Ix i =>UArray i (Ptr a) ->Int ->Ptr a

unsafeReplace ::Ix i =>UArray i (Ptr a) -> [(Int,Ptr a)] ->UArray i (Ptr a)

unsafeAccum ::Ix i => (Ptr a -> e' ->Ptr a) ->UArray i (Ptr a) -> [(Int, e')] ->UArray i (Ptr a)

unsafeAccumArray ::Ix i => (Ptr a -> e' ->Ptr a) ->Ptr a -> (i, i) -> [(Int, e')] ->UArray i (Ptr a)

IArrayUArray (FunPtr a)Source# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>UArray i (FunPtr a) -> (i, i)Source#

numElements ::Ix i =>UArray i (FunPtr a) ->Int

unsafeArray ::Ix i => (i, i) -> [(Int,FunPtr a)] ->UArray i (FunPtr a)

unsafeAt ::Ix i =>UArray i (FunPtr a) ->Int ->FunPtr a

unsafeReplace ::Ix i =>UArray i (FunPtr a) -> [(Int,FunPtr a)] ->UArray i (FunPtr a)

unsafeAccum ::Ix i => (FunPtr a -> e' ->FunPtr a) ->UArray i (FunPtr a) -> [(Int, e')] ->UArray i (FunPtr a)

unsafeAccumArray ::Ix i => (FunPtr a -> e' ->FunPtr a) ->FunPtr a -> (i, i) -> [(Int, e')] ->UArray i (FunPtr a)

moduleData.Ix

Immutable non-strict (boxed) arrays

dataArray i e#

The type of immutable non-strict (boxed) arrays with indices ini and elements ine.

Instances

Instances details
IArrayArray eSource# 
Instance details

Defined inData.Array.Base

Methods

bounds ::Ix i =>Array i e -> (i, i)Source#

numElements ::Ix i =>Array i e ->Int

unsafeArray ::Ix i => (i, i) -> [(Int, e)] ->Array i e

unsafeAt ::Ix i =>Array i e ->Int -> e

unsafeReplace ::Ix i =>Array i e -> [(Int, e)] ->Array i e

unsafeAccum ::Ix i => (e -> e' -> e) ->Array i e -> [(Int, e')] ->Array i e

unsafeAccumArray ::Ix i => (e -> e' -> e) -> e -> (i, i) -> [(Int, e')] ->Array i e

Functor (Array i)

Since: base-2.1

Instance details

Defined inGHC.Arr

Methods

fmap :: (a -> b) ->Array i a ->Array i b#

(<$) :: a ->Array i b ->Array i a#

Foldable (Array i)

Since: base-4.8.0.0

Instance details

Defined inData.Foldable

Methods

fold ::Monoid m =>Array i m -> m#

foldMap ::Monoid m => (a -> m) ->Array i a -> m#

foldMap' ::Monoid m => (a -> m) ->Array i a -> m#

foldr :: (a -> b -> b) -> b ->Array i a -> b#

foldr' :: (a -> b -> b) -> b ->Array i a -> b#

foldl :: (b -> a -> b) -> b ->Array i a -> b#

foldl' :: (b -> a -> b) -> b ->Array i a -> b#

foldr1 :: (a -> a -> a) ->Array i a -> a#

foldl1 :: (a -> a -> a) ->Array i a -> a#

toList ::Array i a -> [a]#

null ::Array i a ->Bool#

length ::Array i a ->Int#

elem ::Eq a => a ->Array i a ->Bool#

maximum ::Ord a =>Array i a -> a#

minimum ::Ord a =>Array i a -> a#

sum ::Num a =>Array i a -> a#

product ::Num a =>Array i a -> a#

Ix i =>Traversable (Array i)

Since: base-2.1

Instance details

Defined inData.Traversable

Methods

traverse ::Applicative f => (a -> f b) ->Array i a -> f (Array i b)#

sequenceA ::Applicative f =>Array i (f a) -> f (Array i a)#

mapM ::Monad m => (a -> m b) ->Array i a -> m (Array i b)#

sequence ::Monad m =>Array i (m a) -> m (Array i a)#

(Ix i,Eq e) =>Eq (Array i e)

Since: base-2.1

Instance details

Defined inGHC.Arr

Methods

(==) ::Array i e ->Array i e ->Bool#

(/=) ::Array i e ->Array i e ->Bool#

(Ix i,Ord e) =>Ord (Array i e)

Since: base-2.1

Instance details

Defined inGHC.Arr

Methods

compare ::Array i e ->Array i e ->Ordering#

(<) ::Array i e ->Array i e ->Bool#

(<=) ::Array i e ->Array i e ->Bool#

(>) ::Array i e ->Array i e ->Bool#

(>=) ::Array i e ->Array i e ->Bool#

max ::Array i e ->Array i e ->Array i e#

min ::Array i e ->Array i e ->Array i e#

(Ix a,Read a,Read b) =>Read (Array a b)

Since: base-2.1

Instance details

Defined inGHC.Read

(Ix a,Show a,Show b) =>Show (Array a b)

Since: base-2.1

Instance details

Defined inGHC.Arr

Methods

showsPrec ::Int ->Array a b ->ShowS#

show ::Array a b ->String#

showList :: [Array a b] ->ShowS#

Array construction

arraySource#

Arguments

:: (IArray a e,Ix i) 
=> (i, i)

bounds of the array: (lowest,highest)

-> [(i, e)]

list of associations

-> a i e 

Constructs an immutable array from a pair of bounds and a list ofinitial associations.

The bounds are specified as a pair of the lowest and highest bounds inthe array respectively. For example, a one-origin vector of length 10has bounds (1,10), and a one-origin 10 by 10 matrix has bounds((1,1),(10,10)).

An association is a pair of the form(i,x), which defines the value ofthe array at indexi to bex. The array is undefined if any indexin the list is out of bounds. If any two associations in the list havethe same index, the value at that index is implementation-dependent.(In GHC, the last value specified for that index is used.Other implementations will also do this for unboxed arrays, but Haskell98 requires that forArray the value at such indices is bottom.)

Because the indices must be checked for these errors,array isstrict in the bounds argument and in the indices of the associationlist. Whetherarray is strict or non-strict in the elements dependson the array type:Array is a non-strict array type, butall of theUArray arrays are strict. Thus in anon-strict array, recurrences such as the following are possible:

a = array (1,100) ((1,1) : [(i, i * a!(i-1)) | i \<- [2..100]])

Not every index within the bounds of the array need appear in theassociation list, but the values associated with indices that do notappear will be undefined.

If, in any dimension, the lower bound is greater than the upper bound,then the array is legal, but empty. Indexing an empty array alwaysgives an array-bounds error, butbounds still yields the bounds withwhich the array was constructed.

listArray :: (IArray a e,Ix i) => (i, i) -> [e] -> a i eSource#

Constructs an immutable array from a list of initial elements. The list gives the elements of the array in ascending order beginning with the lowest index.

accumArraySource#

Arguments

:: (IArray a e,Ix i) 
=> (e -> e' -> e)

An accumulating function

-> e

A default element

-> (i, i)

The bounds of the array

-> [(i, e')]

List of associations

-> a i e

Returns: the array

Constructs an immutable array from a list of associations. Unlikearray, the same index is allowed to occur multiple times in the listof associations; anaccumulating function is used to combine thevalues of elements with the same index.

For example, given a list of values of some index type, hist producesa histogram of the number of occurrences of each index within aspecified range:

hist :: (Ix a, Num b) => (a,a) -> [a] -> Array a bhist bnds is = accumArray (+) 0 bnds [(i, 1) | i\<-is, inRange bnds i]

Accessing arrays

(!) :: (IArray a e,Ix i) => a i e -> i -> eSource#

Returns the element of an immutable array at the specified index.

bounds :: (IArray a e,Ix i) => a i e -> (i, i)Source#

Extracts the bounds of an immutable array

indices :: (IArray a e,Ix i) => a i e -> [i]Source#

Returns a list of all the valid indices in an array.

elems :: (IArray a e,Ix i) => a i e -> [e]Source#

Returns a list of all the elements of an array, in the same order as their indices.

assocs :: (IArray a e,Ix i) => a i e -> [(i, e)]Source#

Returns the contents of an array as a list of associations.

Incremental array updates

(//) :: (IArray a e,Ix i) => a i e -> [(i, e)] -> a i eSource#

Takes an array and a list of pairs and returns an array identical tothe left argument except that it has been updated by the associationsin the right argument. For example, if m is a 1-origin, n by n matrix,thenm//[((i,i), 0) | i <- [1..n]] is the same matrix, except withthe diagonal zeroed.

As with thearray function, if any two associations in the list havethe same index, the value at that index is implementation-dependent.(In GHC, the last value specified for that index is used.Other implementations will also do this for unboxed arrays, but Haskell98 requires that forArray the value at such indices is bottom.)

For most array types, this operation is O(n) wheren is the sizeof the array. However, the diffarray package provides an array typefor which this operation has complexity linear in the number of updates.

accum :: (IArray a e,Ix i) => (e -> e' -> e) -> a i e -> [(i, e')] -> a i eSource#

accum f takes an array and an association list and accumulates pairsfrom the list into the array with the accumulating functionf. ThusaccumArray can be defined usingaccum:

accumArray f z b = accum f (array b [(i, z) | i \<- range b])

Derived arrays

amap :: (IArray a e',IArray a e,Ix i) => (e' -> e) -> a i e' -> a i eSource#

Returns a new array derived from the original array by applying a function to each of the elements.

ixmap :: (IArray a e,Ix i,Ix j) => (i, i) -> (i -> j) -> a j e -> a i eSource#

Returns a new array derived from the original array by applying a function to each of the indices.

Produced byHaddock version 2.23.0


[8]ページ先頭

©2009-2025 Movatter.jp