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