1 {-# OPTIONS_GHC -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
5 -- Copyright : (c) The University of Glasgow 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : libraries@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
12 -- Basic non-strict arrays.
14 -- /Note:/ The "Data.Array.IArray" module provides more general interface
15 -- to immutable arrays: it defines operations with the same names as
16 -- those defined below, but with more general types, and also defines
17 -- 'Array' instances of the relevant classes. To use that more general
18 -- interface, import "Data.Array.IArray" but not "Data.Array".
19 -----------------------------------------------------------------------------
24 -- * Immutable non-strict arrays
26 module Data.Ix -- export all of Ix
27 , Array -- Array type is abstract
29 -- * Array construction
30 , array -- :: (Ix a) => (a,a) -> [(a,b)] -> Array a b
31 , listArray -- :: (Ix a) => (a,a) -> [b] -> Array a b
32 , accumArray -- :: (Ix a) => (b -> c -> b) -> b -> (a,a) -> [(a,c)] -> Array a b
34 , (!) -- :: (Ix a) => Array a b -> a -> b
35 , bounds -- :: (Ix a) => Array a b -> (a,a)
36 , indices -- :: (Ix a) => Array a b -> [a]
37 , elems -- :: (Ix a) => Array a b -> [b]
38 , assocs -- :: (Ix a) => Array a b -> [(a,b)]
39 -- * Incremental array updates
40 , (//) -- :: (Ix a) => Array a b -> [(a,b)] -> Array a b
41 , accum -- :: (Ix a) => (b -> c -> b) -> Array a b -> [(a,c)] -> Array a b
43 , ixmap -- :: (Ix a, Ix b) => (a,a) -> (a -> b) -> Array b c -> Array a b
47 -- Ix a => Functor (Array a)
48 -- (Ix a, Eq b) => Eq (Array a b)
49 -- (Ix a, Ord b) => Ord (Array a b)
50 -- (Ix a, Show a, Show b) => Show (Array a b)
51 -- (Ix a, Read a, Read b) => Read (Array a b)
54 -- Implementation checked wrt. Haskell 98 lib report, 1/99.
60 #ifdef __GLASGOW_HASKELL__
61 import GHC.Arr -- Most of the hard work is done here
62 import Data.Generics.Basics -- To provide a Data instance
63 import Data.Generics.Instances -- To provide a Data instance
64 import GHC.Err ( error ) -- Needed for Data instance
72 import Array -- Haskell'98 arrays
78 Haskell provides indexable /arrays/, which may be thought of as functions
79 whose domains are isomorphic to contiguous subsets of the integers.
80 Functions restricted in this way can be implemented efficiently;
81 in particular, a programmer may reasonably expect rapid access to
82 the components. To ensure the possibility of such an implementation,
83 arrays are treated as data, not as general functions.
85 Since most array functions involve the class 'Ix', this module is exported
86 from "Data.Array" so that modules need not import both "Data.Array" and