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

ModuleAgda-2.7.0.1Haskell2010

Agda.Utils.IArray

Array utilities.

  • 1 type
  • 2 classes
  • 21 values
  • PackageAgda-2.7.0.1
  • Exports24
  • LanguageHaskell2010
  • LicenceMIT
  • SourceIArray.hs
valuearray
  1. :: (IArray a e, Ix i)
  2. => (i, i)

    bounds of the array: (lowest,highest)

  3. -> [(i, e)]

    list of associations

  4. -> a i e
#

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

The bounds are specified as a pair of the lowest and highest bounds in the array respectively. For example, a one-origin vector of length 10 has 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 of the array at index i to be x. The array is undefined if any index in the list is out of bounds. If any two associations in the list have the 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 Haskell 98 requires that for Array the value at such indices is bottom.)

Because the indices must be checked for these errors, array is strict in the bounds argument and in the indices of the association list. Whether array is strict or non-strict in the elements depends on the array type: Array is a non-strict array type, but all of the UArray arrays are strict. Thus in a non-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 the association list, but the values associated with indices that do not appear 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 always gives an array-bounds error, but bounds still yields the bounds with which the array was constructed.

datadata Array i e
#

The type of immutable non-strict (boxed) arrays with indices in i and elements in e.

Instances29NFData2, IArray, RegexContext, FoldableWithIndex, FunctorWithIndex, TraversableWithIndex, …
classclass IArray (a :: Type -> Type -> Type) e where
#

Class of immutable array types.

An array type has the form (a i e) where a is the array type constructor (kind * -> * -> *), i is the index type (a member of the class Ix), and e is the element type. The IArray class is parameterised over both a and e, so that instances specialised to certain element types can be defined.

Methods

  • bounds :: Ix i => a i e -> (i, i)

    Extracts the bounds of an immutable array

Instances18IArray, …
valuelistArray :: (IArray a e, Ix i) => (i, i) -> [e] -> a i e
#

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.

classclass Ord a => Ix a where
#

The Ix class is used to map a contiguous subrange of values in a type onto integers. It is used primarily for array indexing (see the array package).

The first argument (l,u) of each of these operations is a pair specifying the lower and upper bounds of a contiguous subrange of values.

An implementation is entitled to assume the following laws about these operations:

Methods

  • range :: (a, a) -> [a]

    The list of values in the subrange defined by a bounding pair.

  • index :: (a, a) -> a -> Int

    The position of a subscript in the subrange.

  • inRange :: (a, a) -> a -> Bool

    Returns True the given subscript lies in the range defined the bounding pair.

  • rangeSize :: (a, a) -> Int

    The size of the subrange defined by a bounding pair.

Instances105Ix, …
  • Ix AllowedReductionDefined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.Base
  • Ix FunctionFlagDefined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.Base
  • Ix BlinkSpeedDefined in ansi-terminal-types-1.1.3 · System.Console.ANSI.Types
  • Ix ColorDefined in ansi-terminal-types-1.1.3 · System.Console.ANSI.Types
  • Ix ColorIntensityDefined in ansi-terminal-types-1.1.3 · System.Console.ANSI.Types
  • Ix ConsoleIntensityDefined in ansi-terminal-types-1.1.3 · System.Console.ANSI.Types
  • Ix ConsoleLayerDefined in ansi-terminal-types-1.1.3 · System.Console.ANSI.Types
  • Ix UnderliningDefined in ansi-terminal-types-1.1.3 · System.Console.ANSI.Types
  • Ix IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix CBoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CLLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CPtrdiffDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CSCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CSigAtomicDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CUCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CUIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CUIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CUIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CULLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CULongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CUShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix CWcharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ix IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Ptr
  • Ix WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Ptr
  • Ix AssociativityDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ix DecidedStrictnessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ix SourceStrictnessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ix SourceUnpackednessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ix SeekModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Device
  • Ix IOModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.IOMode
  • Ix Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Ix Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Ix Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Ix Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Ix CBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CBlkSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CClockIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CDevDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CFsBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CFsFilCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CGidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CInoDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CKeyDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CModeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CNfdsDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CNlinkDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix COffDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CPidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CRLimDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CSocklenDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CSsizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CTcflagDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix CUidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix GeneralCategoryDefined in ghc-internal-9.1003.0 · GHC.Internal.Unicode
  • Ix Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ix Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ix Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ix Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ix BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix CharDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix OrderingDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix WordDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix PeanoDefined in peano-0.1.0.2 · Data.Peano
  • Ix DayDefined in time-1.12.2 · Data.Time.Calendar.Days
  • Ix MonthDefined in time-1.12.2 · Data.Time.Calendar.Month
  • Ix QuarterDefined in time-1.12.2 · Data.Time.Calendar.Quarter
  • Ix QuarterOfYearDefined in time-1.12.2 · Data.Time.Calendar.Quarter
  • Ix DayOfWeekDefined in time-1.12.2 · Data.Time.Calendar.Week
  • Ix ()Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix a => Ix (Large a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Modifiers
  • Ix a => Ix (Small a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Modifiers
  • Ix a => Ix (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identity
  • Ix a => Ix (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Ord
  • Ix a => Ix (a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix i => Ix (MIx i)Defined in Agda-2.7.0.1 · Agda.Termination.SparseMatrix
  • Ix (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • (Ix a, Ix b) => Ix (Pair a b)Defined in strict-0.5.1 · Data.Strict.Tuple
  • (Ix a, Ix b) => Ix (a, b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Ix a => Ix (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const
  • Ix b => Ix (Tagged s b)Defined in tagged-0.8.9 · Data.Tagged
  • (Ix a1, Ix a2, Ix a3) => Ix (a1, a2, a3)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4) => Ix (a1, a2, a3, a4)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5) => Ix (a1, a2, a3, a4, a5)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6) => Ix (a1, a2, a3, a4, a5, a6)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6, Ix a7) => Ix (a1, a2, a3, a4, a5, a6, a7)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6, Ix a7, Ix a8) => Ix (a1, a2, a3, a4, a5, a6, a7, a8)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6, Ix a7, Ix a8, Ix a9) => Ix (a1, a2, a3, a4, a5, a6, a7, a8, a9)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6, Ix a7, Ix a8, Ix a9, Ix aA) => Ix (a1, a2, a3, a4, a5, a6, a7, a8, a9, aA)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6, Ix a7, Ix a8, Ix a9, Ix aA, Ix aB) => Ix (a1, a2, a3, a4, a5, a6, a7, a8, a9, aA, aB)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6, Ix a7, Ix a8, Ix a9, Ix aA, Ix aB, Ix aC) => Ix (a1, a2, a3, a4, a5, a6, a7, a8, a9, aA, aB, aC)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6, Ix a7, Ix a8, Ix a9, Ix aA, Ix aB, Ix aC, Ix aD) => Ix (a1, a2, a3, a4, a5, a6, a7, a8, a9, aA, aB, aC, aD)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6, Ix a7, Ix a8, Ix a9, Ix aA, Ix aB, Ix aC, Ix aD, Ix aE) => Ix (a1, a2, a3, a4, a5, a6, a7, a8, a9, aA, aB, aC, aD, aE)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5, Ix a6, Ix a7, Ix a8, Ix a9, Ix aA, Ix aB, Ix aC, Ix aD, Ix aE, Ix aF) => Ix (a1, a2, a3, a4, a5, a6, a7, a8, a9, aA, aB, aC, aD, aE, aF)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ix
valueelems :: (IArray a e, Ix i) => a i e -> [e]
#

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

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

Returns the element of an immutable array at the specified index, or throws an exception if the index is out of bounds.

value(!?) :: (IArray a e, Ix i) => a i e -> i -> Maybe e
#

Returns Just the element of an immutable array at the specified index, or Nothing if the index is out of bounds.

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

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

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

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

As with the array function, if any two associations in the list have the 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 Haskell 98 requires that for Array the value at such indices is bottom.)

For most array types, this operation is O(n) where n is the size of the array. However, the diffarray package provides an array type for which this operation has complexity linear in the number of updates.

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

accum f takes an array and an association list and accumulates pairs from the list into the array with the accumulating function f. Thus accumArray can be defined using accum:

accumArray f z b = accum f (array b [(i, z) | i \<- range b])
valueamap :: (IArray a e', IArray a e, Ix i) => (e' -> e) -> a i e' -> a i e
#

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

valueaccumArray
  1. :: (IArray a e, Ix i)
  2. => (e -> e' -> e)

    An accumulating function

  3. -> e

    A default element

  4. -> (i, i)

    The bounds of the array

  5. -> [(i, e')]

    List of associations

  6. -> a i e

    Returns: the array

#

Constructs an immutable array from a list of associations. Unlike array, the same index is allowed to occur multiple times in the list of associations; an accumulating function is used to combine the values of elements with the same index.

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

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

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

valuefoldlArray :: (IArray a e, Ix i) => (b -> e -> b) -> b -> a i e -> b
#

Lazy left-associative fold.

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

Strict accumulating left-associative fold.

valuefoldlArrayM'
  1. :: (IArray a e, Ix i, Monad m)
  2. => b -> e -> m b
  3. -> b
  4. -> a i e
  5. -> m b
#

Strict accumulating left-associative monadic fold.

valuefoldrArray :: (IArray a e, Ix i) => (e -> b -> b) -> b -> a i e -> b
#

Lazy right-associative fold.

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

Strict accumulating right-associative fold.

valuefoldrArrayM'
  1. :: (IArray a e, Ix i, Monad m)
  2. => e -> b -> m b
  3. -> b
  4. -> a i e
  5. -> m b
#

Strict accumulating right-associative monadic fold.

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

Constructs an immutable array using a generator function.

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

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

valuetraverseArray_
  1. :: (IArray a e, Ix i, Applicative f)
  2. => e -> f b
  3. -> a i e
  4. -> f ()
#

Map elements to applicative actions, sequence them left-to-right, and discard the results.