Add unsafeIndex, unsafeLast etc.
[darcs-mirrors/vector.git] / Data / Vector.hs
1 {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies #-}
2
3 -- |
4 -- Module : Data.Vector
5 -- Copyright : (c) Roman Leshchinskiy 2008-2009
6 -- License : BSD-style
7 --
8 -- Maintainer : Roman Leshchinskiy <rl@cse.unsw.edu.au>
9 -- Stability : experimental
10 -- Portability : non-portable
11 --
12 -- Boxed vectors
13 --
14
15 module Data.Vector (
16 Vector, MVector,
17
18 -- * Length information
19 length, null,
20
21 -- * Construction
22 empty, singleton, cons, snoc, replicate, generate, (++), copy,
23
24 -- * Accessing individual elements
25 (!), head, last, indexM, headM, lastM,
26 unsafeIndex, unsafeHead, unsafeLast,
27 unsafeIndexM, unsafeHeadM, unsafeLastM,
28
29 -- * Subvectors
30 slice, init, tail, take, drop,
31 unsafeSlice,
32
33 -- * Permutations
34 accum, accumulate, accumulate_,
35 (//), update, update_,
36 backpermute, reverse,
37
38 -- * Mapping
39 map, imap, concatMap,
40
41 -- * Zipping and unzipping
42 zipWith, zipWith3, zipWith4, zipWith5, zipWith6,
43 izipWith, izipWith3, izipWith4, izipWith5, izipWith6,
44 zip, zip3, zip4, zip5, zip6,
45 unzip, unzip3, unzip4, unzip5, unzip6,
46
47 -- * Filtering
48 filter, ifilter, takeWhile, dropWhile,
49 unstablePartition, span, break,
50
51 -- * Searching
52 elem, notElem, find, findIndex, findIndices, elemIndex, elemIndices,
53
54 -- * Folding
55 foldl, foldl1, foldl', foldl1', foldr, foldr1,
56 ifoldl, ifoldl', ifoldr,
57
58 -- * Specialised folds
59 all, any, and, or,
60 sum, product,
61 maximum, maximumBy, minimum, minimumBy,
62 minIndex, minIndexBy, maxIndex, maxIndexBy,
63
64 -- * Unfolding
65 unfoldr,
66
67 -- * Scans
68 prescanl, prescanl',
69 postscanl, postscanl',
70 scanl, scanl', scanl1, scanl1',
71
72 -- * Enumeration
73 enumFromTo, enumFromThenTo,
74
75 -- * Conversion to/from lists
76 toList, fromList,
77
78 -- * Unsafe operations
79 unsafeAccum, unsafeAccumulate, unsafeAccumulate_,
80 unsafeUpd, unsafeUpdate, unsafeUpdate_
81 ) where
82
83 import qualified Data.Vector.Generic as G
84 import Data.Vector.Mutable ( MVector(..) )
85 import Data.Primitive.Array
86
87 import Control.Monad ( liftM )
88
89 import Prelude hiding ( length, null,
90 replicate, (++),
91 head, last,
92 init, tail, take, drop, reverse,
93 map, concatMap,
94 zipWith, zipWith3, zip, zip3, unzip, unzip3,
95 filter, takeWhile, dropWhile, span, break,
96 elem, notElem,
97 foldl, foldl1, foldr, foldr1,
98 all, any, and, or, sum, product, minimum, maximum,
99 scanl, scanl1,
100 enumFromTo, enumFromThenTo )
101
102 import qualified Prelude
103
104 data Vector a = Vector {-# UNPACK #-} !Int
105 {-# UNPACK #-} !Int
106 {-# UNPACK #-} !(Array a)
107
108 instance Show a => Show (Vector a) where
109 show = (Prelude.++ " :: Data.Vector.Vector") . ("fromList " Prelude.++) . show . toList
110
111 type instance G.Mutable Vector = MVector
112
113 instance G.Vector Vector a where
114 {-# INLINE unsafeFreeze #-}
115 unsafeFreeze (MVector i n marr)
116 = Vector i n `liftM` unsafeFreezeArray marr
117
118 {-# INLINE basicLength #-}
119 basicLength (Vector _ n _) = n
120
121 {-# INLINE basicUnsafeSlice #-}
122 basicUnsafeSlice (Vector i _ arr) j n = Vector (i+j) n arr
123
124 {-# INLINE basicUnsafeIndexM #-}
125 basicUnsafeIndexM (Vector i _ arr) j = indexArrayM arr (i+j)
126
127 instance Eq a => Eq (Vector a) where
128 {-# INLINE (==) #-}
129 (==) = G.eq
130
131 instance Ord a => Ord (Vector a) where
132 {-# INLINE compare #-}
133 compare = G.cmp
134
135 -- Length
136 -- ------
137
138 length :: Vector a -> Int
139 {-# INLINE length #-}
140 length = G.length
141
142 null :: Vector a -> Bool
143 {-# INLINE null #-}
144 null = G.null
145
146 -- Construction
147 -- ------------
148
149 -- | Empty vector
150 empty :: Vector a
151 {-# INLINE empty #-}
152 empty = G.empty
153
154 -- | Vector with exaclty one element
155 singleton :: a -> Vector a
156 {-# INLINE singleton #-}
157 singleton = G.singleton
158
159 -- | Vector of the given length with the given value in each position
160 replicate :: Int -> a -> Vector a
161 {-# INLINE replicate #-}
162 replicate = G.replicate
163
164 -- | Generate a vector of the given length by applying the function to each
165 -- index
166 generate :: Int -> (Int -> a) -> Vector a
167 {-# INLINE generate #-}
168 generate = G.generate
169
170 -- | Prepend an element
171 cons :: a -> Vector a -> Vector a
172 {-# INLINE cons #-}
173 cons = G.cons
174
175 -- | Append an element
176 snoc :: Vector a -> a -> Vector a
177 {-# INLINE snoc #-}
178 snoc = G.snoc
179
180 infixr 5 ++
181 -- | Concatenate two vectors
182 (++) :: Vector a -> Vector a -> Vector a
183 {-# INLINE (++) #-}
184 (++) = (G.++)
185
186 -- | Create a copy of a vector. Useful when dealing with slices.
187 copy :: Vector a -> Vector a
188 {-# INLINE copy #-}
189 copy = G.copy
190
191 -- Accessing individual elements
192 -- -----------------------------
193
194 -- | Indexing
195 (!) :: Vector a -> Int -> a
196 {-# INLINE (!) #-}
197 (!) = (G.!)
198
199 -- | First element
200 head :: Vector a -> a
201 {-# INLINE head #-}
202 head = G.head
203
204 -- | Last element
205 last :: Vector a -> a
206 {-# INLINE last #-}
207 last = G.last
208
209 -- | Unsafe indexing without bounds checking
210 unsafeIndex :: Vector a -> Int -> a
211 {-# INLINE unsafeIndex #-}
212 unsafeIndex = G.unsafeIndex
213
214 -- | Yield the first element of a vector without checking if the vector is
215 -- empty
216 unsafeHead :: Vector a -> a
217 {-# INLINE unsafeHead #-}
218 unsafeHead = G.unsafeHead
219
220 -- | Yield the last element of a vector without checking if the vector is
221 -- empty
222 unsafeLast :: Vector a -> a
223 {-# INLINE unsafeLast #-}
224 unsafeLast = G.unsafeLast
225
226 -- | Monadic indexing which can be strict in the vector while remaining lazy in
227 -- the element
228 indexM :: Monad m => Vector a -> Int -> m a
229 {-# INLINE indexM #-}
230 indexM = G.indexM
231
232 headM :: Monad m => Vector a -> m a
233 {-# INLINE headM #-}
234 headM = G.headM
235
236 lastM :: Monad m => Vector a -> m a
237 {-# INLINE lastM #-}
238 lastM = G.lastM
239
240 -- | Unsafe monadic indexing without bounds checks
241 unsafeIndexM :: Monad m => Vector a -> Int -> m a
242 {-# INLINE unsafeIndexM #-}
243 unsafeIndexM = G.unsafeIndexM
244
245 unsafeHeadM :: Monad m => Vector a -> m a
246 {-# INLINE unsafeHeadM #-}
247 unsafeHeadM = G.unsafeHeadM
248
249 unsafeLastM :: Monad m => Vector a -> m a
250 {-# INLINE unsafeLastM #-}
251 unsafeLastM = G.unsafeLastM
252
253 -- Subarrays
254 -- ---------
255
256 -- | Yield a part of the vector without copying it. Safer version of
257 -- 'basicUnsafeSlice'.
258 slice :: Vector a -> Int -- ^ starting index
259 -> Int -- ^ length
260 -> Vector a
261 {-# INLINE slice #-}
262 slice = G.slice
263
264 -- | Unsafely yield a part of the vector without copying it and without
265 -- performing bounds checks.
266 unsafeSlice :: Vector a -> Int -- ^ starting index
267 -> Int -- ^ length
268 -> Vector a
269 {-# INLINE unsafeSlice #-}
270 unsafeSlice = G.unsafeSlice
271
272 -- | Yield all but the last element without copying.
273 init :: Vector a -> Vector a
274 {-# INLINE init #-}
275 init = G.init
276
277 -- | All but the first element (without copying).
278 tail :: Vector a -> Vector a
279 {-# INLINE tail #-}
280 tail = G.tail
281
282 -- | Yield the first @n@ elements without copying.
283 take :: Int -> Vector a -> Vector a
284 {-# INLINE take #-}
285 take = G.take
286
287 -- | Yield all but the first @n@ elements without copying.
288 drop :: Int -> Vector a -> Vector a
289 {-# INLINE drop #-}
290 drop = G.drop
291
292 -- Permutations
293 -- ------------
294
295 unsafeAccum :: (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
296 {-# INLINE unsafeAccum #-}
297 unsafeAccum = G.unsafeAccum
298
299 unsafeAccumulate :: (a -> b -> a) -> Vector a -> Vector (Int,b) -> Vector a
300 {-# INLINE unsafeAccumulate #-}
301 unsafeAccumulate = G.unsafeAccumulate
302
303 unsafeAccumulate_
304 :: (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
305 {-# INLINE unsafeAccumulate_ #-}
306 unsafeAccumulate_ = G.unsafeAccumulate_
307
308 accum :: (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
309 {-# INLINE accum #-}
310 accum = G.accum
311
312 accumulate :: (a -> b -> a) -> Vector a -> Vector (Int,b) -> Vector a
313 {-# INLINE accumulate #-}
314 accumulate = G.accumulate
315
316 accumulate_ :: (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
317 {-# INLINE accumulate_ #-}
318 accumulate_ = G.accumulate_
319
320 unsafeUpd :: Vector a -> [(Int, a)] -> Vector a
321 {-# INLINE unsafeUpd #-}
322 unsafeUpd = G.unsafeUpd
323
324 unsafeUpdate :: Vector a -> Vector (Int, a) -> Vector a
325 {-# INLINE unsafeUpdate #-}
326 unsafeUpdate = G.unsafeUpdate
327
328 unsafeUpdate_ :: Vector a -> Vector Int -> Vector a -> Vector a
329 {-# INLINE unsafeUpdate_ #-}
330 unsafeUpdate_ = G.unsafeUpdate_
331
332 (//) :: Vector a -> [(Int, a)] -> Vector a
333 {-# INLINE (//) #-}
334 (//) = (G.//)
335
336 update :: Vector a -> Vector (Int, a) -> Vector a
337 {-# INLINE update #-}
338 update = G.update
339
340 update_ :: Vector a -> Vector Int -> Vector a -> Vector a
341 {-# INLINE update_ #-}
342 update_ = G.update_
343
344 backpermute :: Vector a -> Vector Int -> Vector a
345 {-# INLINE backpermute #-}
346 backpermute = G.backpermute
347
348 reverse :: Vector a -> Vector a
349 {-# INLINE reverse #-}
350 reverse = G.reverse
351
352 -- Mapping
353 -- -------
354
355 -- | Map a function over a vector
356 map :: (a -> b) -> Vector a -> Vector b
357 {-# INLINE map #-}
358 map = G.map
359
360 -- | Apply a function to every index/value pair
361 imap :: (Int -> a -> b) -> Vector a -> Vector b
362 {-# INLINE imap #-}
363 imap = G.imap
364
365 concatMap :: (a -> Vector b) -> Vector a -> Vector b
366 {-# INLINE concatMap #-}
367 concatMap = G.concatMap
368
369 -- Zipping/unzipping
370 -- -----------------
371
372 -- | Zip two vectors with the given function.
373 zipWith :: (a -> b -> c) -> Vector a -> Vector b -> Vector c
374 {-# INLINE zipWith #-}
375 zipWith = G.zipWith
376
377 -- | Zip three vectors with the given function.
378 zipWith3 :: (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d
379 {-# INLINE zipWith3 #-}
380 zipWith3 = G.zipWith3
381
382 zipWith4 :: (a -> b -> c -> d -> e)
383 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
384 {-# INLINE zipWith4 #-}
385 zipWith4 = G.zipWith4
386
387 zipWith5 :: (a -> b -> c -> d -> e -> f)
388 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
389 -> Vector f
390 {-# INLINE zipWith5 #-}
391 zipWith5 = G.zipWith5
392
393 zipWith6 :: (a -> b -> c -> d -> e -> f -> g)
394 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
395 -> Vector f -> Vector g
396 {-# INLINE zipWith6 #-}
397 zipWith6 = G.zipWith6
398
399 -- | Zip two vectors and their indices with the given function.
400 izipWith :: (Int -> a -> b -> c) -> Vector a -> Vector b -> Vector c
401 {-# INLINE izipWith #-}
402 izipWith = G.izipWith
403
404 -- | Zip three vectors and their indices with the given function.
405 izipWith3 :: (Int -> a -> b -> c -> d)
406 -> Vector a -> Vector b -> Vector c -> Vector d
407 {-# INLINE izipWith3 #-}
408 izipWith3 = G.izipWith3
409
410 izipWith4 :: (Int -> a -> b -> c -> d -> e)
411 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
412 {-# INLINE izipWith4 #-}
413 izipWith4 = G.izipWith4
414
415 izipWith5 :: (Int -> a -> b -> c -> d -> e -> f)
416 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
417 -> Vector f
418 {-# INLINE izipWith5 #-}
419 izipWith5 = G.izipWith5
420
421 izipWith6 :: (Int -> a -> b -> c -> d -> e -> f -> g)
422 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
423 -> Vector f -> Vector g
424 {-# INLINE izipWith6 #-}
425 izipWith6 = G.izipWith6
426
427 zip :: Vector a -> Vector b -> Vector (a, b)
428 {-# INLINE zip #-}
429 zip = G.zip
430
431 zip3 :: Vector a -> Vector b -> Vector c -> Vector (a, b, c)
432 {-# INLINE zip3 #-}
433 zip3 = G.zip3
434
435 zip4 :: Vector a -> Vector b -> Vector c -> Vector d
436 -> Vector (a, b, c, d)
437 {-# INLINE zip4 #-}
438 zip4 = G.zip4
439
440 zip5 :: Vector a -> Vector b -> Vector c -> Vector d -> Vector e
441 -> Vector (a, b, c, d, e)
442 {-# INLINE zip5 #-}
443 zip5 = G.zip5
444
445 zip6 :: Vector a -> Vector b -> Vector c -> Vector d -> Vector e -> Vector f
446 -> Vector (a, b, c, d, e, f)
447 {-# INLINE zip6 #-}
448 zip6 = G.zip6
449
450 unzip :: Vector (a, b) -> (Vector a, Vector b)
451 {-# INLINE unzip #-}
452 unzip = G.unzip
453
454 unzip3 :: Vector (a, b, c) -> (Vector a, Vector b, Vector c)
455 {-# INLINE unzip3 #-}
456 unzip3 = G.unzip3
457
458 unzip4 :: Vector (a, b, c, d) -> (Vector a, Vector b, Vector c, Vector d)
459 {-# INLINE unzip4 #-}
460 unzip4 = G.unzip4
461
462 unzip5 :: Vector (a, b, c, d, e)
463 -> (Vector a, Vector b, Vector c, Vector d, Vector e)
464 {-# INLINE unzip5 #-}
465 unzip5 = G.unzip5
466
467 unzip6 :: Vector (a, b, c, d, e, f)
468 -> (Vector a, Vector b, Vector c, Vector d, Vector e, Vector f)
469 {-# INLINE unzip6 #-}
470 unzip6 = G.unzip6
471
472 -- Filtering
473 -- ---------
474
475 -- | Drop elements which do not satisfy the predicate
476 filter :: (a -> Bool) -> Vector a -> Vector a
477 {-# INLINE filter #-}
478 filter = G.filter
479
480 -- | Drop elements that do not satisfy the predicate (applied to values and
481 -- their indices)
482 ifilter :: (Int -> a -> Bool) -> Vector a -> Vector a
483 {-# INLINE ifilter #-}
484 ifilter = G.ifilter
485
486 -- | Yield the longest prefix of elements satisfying the predicate.
487 takeWhile :: (a -> Bool) -> Vector a -> Vector a
488 {-# INLINE takeWhile #-}
489 takeWhile = G.takeWhile
490
491 -- | Drop the longest prefix of elements that satisfy the predicate.
492 dropWhile :: (a -> Bool) -> Vector a -> Vector a
493 {-# INLINE dropWhile #-}
494 dropWhile = G.dropWhile
495
496 -- | Split the vector in two parts, the first one containing those elements
497 -- that satisfy the predicate and the second one those that don't. The order
498 -- of the elements is not preserved.
499 unstablePartition :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
500 {-# INLINE unstablePartition #-}
501 unstablePartition = G.unstablePartition
502
503 -- | Split the vector into the longest prefix of elements that satisfy the
504 -- predicate and the rest.
505 span :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
506 {-# INLINE span #-}
507 span = G.span
508
509 -- | Split the vector into the longest prefix of elements that do not satisfy
510 -- the predicate and the rest.
511 break :: (a -> Bool) -> Vector a -> (Vector a, Vector a)
512 {-# INLINE break #-}
513 break = G.break
514
515 -- Searching
516 -- ---------
517
518 infix 4 `elem`
519 -- | Check whether the vector contains an element
520 elem :: Eq a => a -> Vector a -> Bool
521 {-# INLINE elem #-}
522 elem = G.elem
523
524 infix 4 `notElem`
525 -- | Inverse of `elem`
526 notElem :: Eq a => a -> Vector a -> Bool
527 {-# INLINE notElem #-}
528 notElem = G.notElem
529
530 -- | Yield 'Just' the first element matching the predicate or 'Nothing' if no
531 -- such element exists.
532 find :: (a -> Bool) -> Vector a -> Maybe a
533 {-# INLINE find #-}
534 find = G.find
535
536 -- | Yield 'Just' the index of the first element matching the predicate or
537 -- 'Nothing' if no such element exists.
538 findIndex :: (a -> Bool) -> Vector a -> Maybe Int
539 {-# INLINE findIndex #-}
540 findIndex = G.findIndex
541
542 -- | Yield the indices of elements satisfying the predicate
543 findIndices :: (a -> Bool) -> Vector a -> Vector Int
544 {-# INLINE findIndices #-}
545 findIndices = G.findIndices
546
547 -- | Yield 'Just' the index of the first occurence of the given element or
548 -- 'Nothing' if the vector does not contain the element
549 elemIndex :: Eq a => a -> Vector a -> Maybe Int
550 {-# INLINE elemIndex #-}
551 elemIndex = G.elemIndex
552
553 -- | Yield the indices of all occurences of the given element
554 elemIndices :: Eq a => a -> Vector a -> Vector Int
555 {-# INLINE elemIndices #-}
556 elemIndices = G.elemIndices
557
558 -- Folding
559 -- -------
560
561 -- | Left fold
562 foldl :: (a -> b -> a) -> a -> Vector b -> a
563 {-# INLINE foldl #-}
564 foldl = G.foldl
565
566 -- | Lefgt fold on non-empty vectors
567 foldl1 :: (a -> a -> a) -> Vector a -> a
568 {-# INLINE foldl1 #-}
569 foldl1 = G.foldl1
570
571 -- | Left fold with strict accumulator
572 foldl' :: (a -> b -> a) -> a -> Vector b -> a
573 {-# INLINE foldl' #-}
574 foldl' = G.foldl'
575
576 -- | Left fold on non-empty vectors with strict accumulator
577 foldl1' :: (a -> a -> a) -> Vector a -> a
578 {-# INLINE foldl1' #-}
579 foldl1' = G.foldl1'
580
581 -- | Right fold
582 foldr :: (a -> b -> b) -> b -> Vector a -> b
583 {-# INLINE foldr #-}
584 foldr = G.foldr
585
586 -- | Right fold on non-empty vectors
587 foldr1 :: (a -> a -> a) -> Vector a -> a
588 {-# INLINE foldr1 #-}
589 foldr1 = G.foldr1
590
591 -- | Left fold (function applied to each element and its index)
592 ifoldl :: (a -> Int -> b -> a) -> a -> Vector b -> a
593 {-# INLINE ifoldl #-}
594 ifoldl = G.ifoldl
595
596 -- | Left fold with strict accumulator (function applied to each element and
597 -- its index)
598 ifoldl' :: (a -> Int -> b -> a) -> a -> Vector b -> a
599 {-# INLINE ifoldl' #-}
600 ifoldl' = G.ifoldl'
601
602 -- | Right fold (function applied to each element and its index)
603 ifoldr :: (Int -> a -> b -> b) -> b -> Vector a -> b
604 {-# INLINE ifoldr #-}
605 ifoldr = G.ifoldr
606
607 -- Specialised folds
608 -- -----------------
609
610 all :: (a -> Bool) -> Vector a -> Bool
611 {-# INLINE all #-}
612 all = G.all
613
614 any :: (a -> Bool) -> Vector a -> Bool
615 {-# INLINE any #-}
616 any = G.any
617
618 and :: Vector Bool -> Bool
619 {-# INLINE and #-}
620 and = G.and
621
622 or :: Vector Bool -> Bool
623 {-# INLINE or #-}
624 or = G.or
625
626 sum :: Num a => Vector a -> a
627 {-# INLINE sum #-}
628 sum = G.sum
629
630 product :: Num a => Vector a -> a
631 {-# INLINE product #-}
632 product = G.product
633
634 maximum :: Ord a => Vector a -> a
635 {-# INLINE maximum #-}
636 maximum = G.maximum
637
638 maximumBy :: (a -> a -> Ordering) -> Vector a -> a
639 {-# INLINE maximumBy #-}
640 maximumBy = G.maximumBy
641
642 minimum :: Ord a => Vector a -> a
643 {-# INLINE minimum #-}
644 minimum = G.minimum
645
646 minimumBy :: (a -> a -> Ordering) -> Vector a -> a
647 {-# INLINE minimumBy #-}
648 minimumBy = G.minimumBy
649
650 maxIndex :: Ord a => Vector a -> Int
651 {-# INLINE maxIndex #-}
652 maxIndex = G.maxIndex
653
654 maxIndexBy :: (a -> a -> Ordering) -> Vector a -> Int
655 {-# INLINE maxIndexBy #-}
656 maxIndexBy = G.maxIndexBy
657
658 minIndex :: Ord a => Vector a -> Int
659 {-# INLINE minIndex #-}
660 minIndex = G.minIndex
661
662 minIndexBy :: (a -> a -> Ordering) -> Vector a -> Int
663 {-# INLINE minIndexBy #-}
664 minIndexBy = G.minIndexBy
665
666 -- Unfolding
667 -- ---------
668
669 unfoldr :: (b -> Maybe (a, b)) -> b -> Vector a
670 {-# INLINE unfoldr #-}
671 unfoldr = G.unfoldr
672
673 -- Scans
674 -- -----
675
676 -- | Prefix scan
677 prescanl :: (a -> b -> a) -> a -> Vector b -> Vector a
678 {-# INLINE prescanl #-}
679 prescanl = G.prescanl
680
681 -- | Prefix scan with strict accumulator
682 prescanl' :: (a -> b -> a) -> a -> Vector b -> Vector a
683 {-# INLINE prescanl' #-}
684 prescanl' = G.prescanl'
685
686 -- | Suffix scan
687 postscanl :: (a -> b -> a) -> a -> Vector b -> Vector a
688 {-# INLINE postscanl #-}
689 postscanl = G.postscanl
690
691 -- | Suffix scan with strict accumulator
692 postscanl' :: (a -> b -> a) -> a -> Vector b -> Vector a
693 {-# INLINE postscanl' #-}
694 postscanl' = G.postscanl'
695
696 -- | Haskell-style scan
697 scanl :: (a -> b -> a) -> a -> Vector b -> Vector a
698 {-# INLINE scanl #-}
699 scanl = G.scanl
700
701 -- | Haskell-style scan with strict accumulator
702 scanl' :: (a -> b -> a) -> a -> Vector b -> Vector a
703 {-# INLINE scanl' #-}
704 scanl' = G.scanl'
705
706 -- | Scan over a non-empty 'Vector'
707 scanl1 :: (a -> a -> a) -> Vector a -> Vector a
708 {-# INLINE scanl1 #-}
709 scanl1 = G.scanl1
710
711 -- | Scan over a non-empty 'Vector' with a strict accumulator
712 scanl1' :: (a -> a -> a) -> Vector a -> Vector a
713 {-# INLINE scanl1' #-}
714 scanl1' = G.scanl1'
715
716 -- Enumeration
717 -- -----------
718
719 enumFromTo :: Enum a => a -> a -> Vector a
720 {-# INLINE enumFromTo #-}
721 enumFromTo = G.enumFromTo
722
723 enumFromThenTo :: Enum a => a -> a -> a -> Vector a
724 {-# INLINE enumFromThenTo #-}
725 enumFromThenTo = G.enumFromThenTo
726
727 -- Conversion to/from lists
728 -- ------------------------
729
730 -- | Convert a vector to a list
731 toList :: Vector a -> [a]
732 {-# INLINE toList #-}
733 toList = G.toList
734
735 -- | Convert a list to a vector
736 fromList :: [a] -> Vector a
737 {-# INLINE fromList #-}
738 fromList = G.fromList
739