Use Safe Haskell if GHC >= 7.2
[darcs-mirrors/vector.git] / Data / Vector / Safe.hs
1 #if __GLASGOW_HASKELL__ >= 701 && defined(VECTOR_BOUNDS_CHECKS)
2 {-# LANGUAGE Trustworthy #-}
3 #endif
4 -- |
5 -- Module : Data.Vector.Safe
6 -- Copyright : (c) Roman Leshchinskiy 2008-2010
7 -- License : BSD-style
8 --
9 -- Maintainer : Roman Leshchinskiy <rl@cse.unsw.edu.au>
10 -- Stability : experimental
11 -- Portability : non-portable
12 --
13 -- A library for boxed vectors (that is, polymorphic arrays capable of
14 -- holding any Haskell value). The vectors come in two flavors:
15 --
16 -- * mutable
17 --
18 -- * immutable
19 --
20 -- and support a rich interface of both list-like operations, and bulk
21 -- array operations.
22 --
23 -- Safe API only.
24 --
25 -- For unboxed arrays, use the 'Data.Vector.Unboxed' interface.
26 --
27
28 module Data.Vector.Safe (
29 -- * Boxed vectors
30 Vector, MVector,
31
32 -- * Accessors
33
34 -- ** Length information
35 length, null,
36
37 -- ** Indexing
38 (!), (!?), head, last,
39
40 -- ** Monadic indexing
41 indexM, headM, lastM,
42
43 -- ** Extracting subvectors (slicing)
44 slice, init, tail, take, drop, splitAt,
45
46 -- * Construction
47
48 -- ** Initialisation
49 empty, singleton, replicate, generate, iterateN,
50
51 -- ** Monadic initialisation
52 replicateM, generateM, create,
53
54 -- ** Unfolding
55 unfoldr, unfoldrN,
56
57 -- ** Enumeration
58 enumFromN, enumFromStepN, enumFromTo, enumFromThenTo,
59
60 -- ** Concatenation
61 cons, snoc, (++), concat,
62
63 -- ** Restricting memory usage
64 force,
65
66 -- * Modifying vectors
67
68 -- ** Bulk updates
69 (//), update, update_,
70
71 -- ** Accumulations
72 accum, accumulate, accumulate_,
73
74 -- ** Permutations
75 reverse, backpermute,
76
77 -- ** Safe destructive updates
78 modify,
79
80 -- * Elementwise operations
81
82 -- ** Indexing
83 indexed,
84
85 -- ** Mapping
86 map, imap, concatMap,
87
88 -- ** Monadic mapping
89 mapM, mapM_, forM, forM_,
90
91 -- ** Zipping
92 zipWith, zipWith3, zipWith4, zipWith5, zipWith6,
93 izipWith, izipWith3, izipWith4, izipWith5, izipWith6,
94 zip, zip3, zip4, zip5, zip6,
95
96 -- ** Monadic zipping
97 zipWithM, zipWithM_,
98
99 -- ** Unzipping
100 unzip, unzip3, unzip4, unzip5, unzip6,
101
102 -- * Working with predicates
103
104 -- ** Filtering
105 filter, ifilter, filterM,
106 takeWhile, dropWhile,
107
108 -- ** Partitioning
109 partition, unstablePartition, span, break,
110
111 -- ** Searching
112 elem, notElem, find, findIndex, findIndices, elemIndex, elemIndices,
113
114 -- * Folding
115 foldl, foldl1, foldl', foldl1', foldr, foldr1, foldr', foldr1',
116 ifoldl, ifoldl', ifoldr, ifoldr',
117
118 -- ** Specialised folds
119 all, any, and, or,
120 sum, product,
121 maximum, maximumBy, minimum, minimumBy,
122 minIndex, minIndexBy, maxIndex, maxIndexBy,
123
124 -- ** Monadic folds
125 foldM, foldM', fold1M, fold1M',
126 foldM_, foldM'_, fold1M_, fold1M'_,
127
128 -- ** Monadic sequencing
129 sequence, sequence_,
130
131 -- * Prefix sums (scans)
132 prescanl, prescanl',
133 postscanl, postscanl',
134 scanl, scanl', scanl1, scanl1',
135 prescanr, prescanr',
136 postscanr, postscanr',
137 scanr, scanr', scanr1, scanr1',
138
139 -- * Conversions
140
141 -- ** Lists
142 toList, fromList, fromListN,
143
144 -- ** Other vector types
145 G.convert,
146
147 -- ** Mutable vectors
148 freeze, thaw, copy
149 ) where
150
151 import Data.Vector
152