[project @ 2005-01-11 16:04:08 by simonmar]
[packages/old-time.git] / Data / Array.hs
1 {-# OPTIONS_GHC -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module : Data.Array
5 -- Copyright : (c) The University of Glasgow 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
7 --
8 -- Maintainer : libraries@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
11 --
12 -- Basic non-strict arrays.
13 --
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 -----------------------------------------------------------------------------
20
21 module Data.Array
22
23 (
24 -- * Immutable non-strict arrays
25 -- $intro
26 module Data.Ix -- export all of Ix
27 , Array -- Array type is abstract
28
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
33 -- * Accessing arrays
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
42 -- * Derived arrays
43 , ixmap -- :: (Ix a, Ix b) => (a,a) -> (a -> b) -> Array b c -> Array a b
44
45 -- Array instances:
46 --
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)
52 --
53
54 -- Implementation checked wrt. Haskell 98 lib report, 1/99.
55
56 ) where
57
58 import Data.Ix
59
60 #ifdef __GLASGOW_HASKELL__
61 import GHC.Arr -- Most of the hard work is done here
62 import GHC.Err ( undefined )
63 #endif
64
65 #ifdef __HUGS__
66 import Hugs.Array
67 #endif
68
69 #ifdef __NHC__
70 import Array -- Haskell'98 arrays
71 #endif
72
73 #ifndef __NHC__
74 import Data.Typeable
75 #endif
76
77 #ifndef __NHC__
78 #include "Typeable.h"
79 INSTANCE_TYPEABLE2(Array,arrayTc,"Array")
80 #endif
81
82 {- $intro
83 Haskell provides indexable /arrays/, which may be thought of as functions
84 whose domains are isomorphic to contiguous subsets of the integers.
85 Functions restricted in this way can be implemented efficiently;
86 in particular, a programmer may reasonably expect rapid access to
87 the components. To ensure the possibility of such an implementation,
88 arrays are treated as data, not as general functions.
89
90 Since most array functions involve the class 'Ix', this module is exported
91 from "Data.Array" so that modules need not import both "Data.Array" and
92 "Data.Ix".
93 -}