Switch the order of argument to slice and unsafeSlice
[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,
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 -- | Unsafely yield a part of the vector without copying it and without
267 -- performing bounds checks.
268 unsafeSlice :: Prim a => Int -- ^ starting index
269 -> Int -- ^ length
270 -> Vector a
271 -> Vector a
272 {-# INLINE unsafeSlice #-}
273 unsafeSlice = G.unsafeSlice
274
275 -- | Yield all but the last element without copying.
276 init :: Prim a => Vector a -> Vector a
277 {-# INLINE init #-}
278 init = G.init
279
280 -- | All but the first element (without copying).
281 tail :: Prim a => Vector a -> Vector a
282 {-# INLINE tail #-}
283 tail = G.tail
284
285 -- | Yield the first @n@ elements without copying.
286 take :: Prim a => Int -> Vector a -> Vector a
287 {-# INLINE take #-}
288 take = G.take
289
290 -- | Yield all but the first @n@ elements without copying.
291 drop :: Prim a => Int -> Vector a -> Vector a
292 {-# INLINE drop #-}
293 drop = G.drop
294
295 -- Permutations
296 -- ------------
297
298 unsafeAccum :: Prim a => (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
299 {-# INLINE unsafeAccum #-}
300 unsafeAccum = G.unsafeAccum
301
302 unsafeAccumulate_ :: (Prim a, Prim b) =>
303 (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
304 {-# INLINE unsafeAccumulate_ #-}
305 unsafeAccumulate_ = G.unsafeAccumulate_
306
307 accum :: Prim a => (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
308 {-# INLINE accum #-}
309 accum = G.accum
310
311 accumulate_ :: (Prim a, Prim b) =>
312 (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
313 {-# INLINE accumulate_ #-}
314 accumulate_ = G.accumulate_
315
316 unsafeUpd :: Prim a => Vector a -> [(Int, a)] -> Vector a
317 {-# INLINE unsafeUpd #-}
318 unsafeUpd = G.unsafeUpd
319
320 unsafeUpdate_ :: Prim a => Vector a -> Vector Int -> Vector a -> Vector a
321 {-# INLINE unsafeUpdate_ #-}
322 unsafeUpdate_ = G.unsafeUpdate_
323
324 (//) :: Prim a => Vector a -> [(Int, a)] -> Vector a
325 {-# INLINE (//) #-}
326 (//) = (G.//)
327
328 update_ :: Prim a => Vector a -> Vector Int -> Vector a -> Vector a
329 {-# INLINE update_ #-}
330 update_ = G.update_
331
332 backpermute :: Prim a => Vector a -> Vector Int -> Vector a
333 {-# INLINE backpermute #-}
334 backpermute = G.backpermute
335
336 reverse :: Prim a => Vector a -> Vector a
337 {-# INLINE reverse #-}
338 reverse = G.reverse
339
340 -- Mapping
341 -- -------
342
343 -- | Map a function over a vector
344 map :: (Prim a, Prim b) => (a -> b) -> Vector a -> Vector b
345 {-# INLINE map #-}
346 map = G.map
347
348 -- | Apply a function to every index/value pair
349 imap :: (Prim a, Prim b) => (Int -> a -> b) -> Vector a -> Vector b
350 {-# INLINE imap #-}
351 imap = G.imap
352
353 concatMap :: (Prim a, Prim b) => (a -> Vector b) -> Vector a -> Vector b
354 {-# INLINE concatMap #-}
355 concatMap = G.concatMap
356
357 -- Zipping/unzipping
358 -- -----------------
359
360 -- | Zip two vectors with the given function.
361 zipWith :: (Prim a, Prim b, Prim c)
362 => (a -> b -> c) -> Vector a -> Vector b -> Vector c
363 {-# INLINE zipWith #-}
364 zipWith = G.zipWith
365
366 -- | Zip three vectors with the given function.
367 zipWith3 :: (Prim a, Prim b, Prim c, Prim d)
368 => (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d
369 {-# INLINE zipWith3 #-}
370 zipWith3 = G.zipWith3
371
372 zipWith4 :: (Prim a, Prim b, Prim c, Prim d, Prim e)
373 => (a -> b -> c -> d -> e)
374 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
375 {-# INLINE zipWith4 #-}
376 zipWith4 = G.zipWith4
377
378 zipWith5 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f)
379 => (a -> b -> c -> d -> e -> f)
380 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
381 -> Vector f
382 {-# INLINE zipWith5 #-}
383 zipWith5 = G.zipWith5
384
385 zipWith6 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f, Prim g)
386 => (a -> b -> c -> d -> e -> f -> g)
387 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
388 -> Vector f -> Vector g
389 {-# INLINE zipWith6 #-}
390 zipWith6 = G.zipWith6
391
392 -- | Zip two vectors and their indices with the given function.
393 izipWith :: (Prim a, Prim b, Prim c)
394 => (Int -> a -> b -> c) -> Vector a -> Vector b -> Vector c
395 {-# INLINE izipWith #-}
396 izipWith = G.izipWith
397
398 -- | Zip three vectors and their indices with the given function.
399 izipWith3 :: (Prim a, Prim b, Prim c, Prim d)
400 => (Int -> a -> b -> c -> d)
401 -> Vector a -> Vector b -> Vector c -> Vector d
402 {-# INLINE izipWith3 #-}
403 izipWith3 = G.izipWith3
404
405 izipWith4 :: (Prim a, Prim b, Prim c, Prim d, Prim e)
406 => (Int -> a -> b -> c -> d -> e)
407 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
408 {-# INLINE izipWith4 #-}
409 izipWith4 = G.izipWith4
410
411 izipWith5 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f)
412 => (Int -> a -> b -> c -> d -> e -> f)
413 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
414 -> Vector f
415 {-# INLINE izipWith5 #-}
416 izipWith5 = G.izipWith5
417
418 izipWith6 :: (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f, Prim g)
419 => (Int -> a -> b -> c -> d -> e -> f -> g)
420 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
421 -> Vector f -> Vector g
422 {-# INLINE izipWith6 #-}
423 izipWith6 = G.izipWith6
424
425 -- Filtering
426 -- ---------
427
428 -- | Drop elements which do not satisfy the predicate
429 filter :: Prim a => (a -> Bool) -> Vector a -> Vector a
430 {-# INLINE filter #-}
431 filter = G.filter
432
433 -- | Drop elements that do not satisfy the predicate (applied to values and
434 -- their indices)
435 ifilter :: Prim a => (Int -> a -> Bool) -> Vector a -> Vector a
436 {-# INLINE ifilter #-}
437 ifilter = G.ifilter
438
439 -- | Yield the longest prefix of elements satisfying the predicate.
440 takeWhile :: Prim a => (a -> Bool) -> Vector a -> Vector a
441 {-# INLINE takeWhile #-}
442 takeWhile = G.takeWhile
443
444 -- | Drop the longest prefix of elements that satisfy the predicate.
445 dropWhile :: Prim a => (a -> Bool) -> Vector a -> Vector a
446 {-# INLINE dropWhile #-}
447 dropWhile = G.dropWhile
448
449 -- | Split the vector in two parts, the first one containing those elements
450 -- that satisfy the predicate and the second one those that don't. The order
451 -- of the elements is not preserved.
452 unstablePartition :: Prim a => (a -> Bool) -> Vector a -> (Vector a, Vector a)
453 {-# INLINE unstablePartition #-}
454 unstablePartition = G.unstablePartition
455
456 -- | Split the vector into the longest prefix of elements that satisfy the
457 -- predicate and the rest.
458 span :: Prim a => (a -> Bool) -> Vector a -> (Vector a, Vector a)
459 {-# INLINE span #-}
460 span = G.span
461
462 -- | Split the vector into the longest prefix of elements that do not satisfy
463 -- the predicate and the rest.
464 break :: Prim a => (a -> Bool) -> Vector a -> (Vector a, Vector a)
465 {-# INLINE break #-}
466 break = G.break
467
468 -- Searching
469 -- ---------
470
471 infix 4 `elem`
472 -- | Check whether the vector contains an element
473 elem :: (Prim a, Eq a) => a -> Vector a -> Bool
474 {-# INLINE elem #-}
475 elem = G.elem
476
477 infix 4 `notElem`
478 -- | Inverse of `elem`
479 notElem :: (Prim a, Eq a) => a -> Vector a -> Bool
480 {-# INLINE notElem #-}
481 notElem = G.notElem
482
483 -- | Yield 'Just' the first element matching the predicate or 'Nothing' if no
484 -- such element exists.
485 find :: Prim a => (a -> Bool) -> Vector a -> Maybe a
486 {-# INLINE find #-}
487 find = G.find
488
489 -- | Yield 'Just' the index of the first element matching the predicate or
490 -- 'Nothing' if no such element exists.
491 findIndex :: Prim a => (a -> Bool) -> Vector a -> Maybe Int
492 {-# INLINE findIndex #-}
493 findIndex = G.findIndex
494
495 -- | Yield the indices of elements satisfying the predicate
496 findIndices :: Prim a => (a -> Bool) -> Vector a -> Vector Int
497 {-# INLINE findIndices #-}
498 findIndices = G.findIndices
499
500 -- | Yield 'Just' the index of the first occurence of the given element or
501 -- 'Nothing' if the vector does not contain the element
502 elemIndex :: (Prim a, Eq a) => a -> Vector a -> Maybe Int
503 {-# INLINE elemIndex #-}
504 elemIndex = G.elemIndex
505
506 -- | Yield the indices of all occurences of the given element
507 elemIndices :: (Prim a, Eq a) => a -> Vector a -> Vector Int
508 {-# INLINE elemIndices #-}
509 elemIndices = G.elemIndices
510
511 -- Folding
512 -- -------
513
514 -- | Left fold
515 foldl :: Prim b => (a -> b -> a) -> a -> Vector b -> a
516 {-# INLINE foldl #-}
517 foldl = G.foldl
518
519 -- | Lefgt fold on non-empty vectors
520 foldl1 :: Prim a => (a -> a -> a) -> Vector a -> a
521 {-# INLINE foldl1 #-}
522 foldl1 = G.foldl1
523
524 -- | Left fold with strict accumulator
525 foldl' :: Prim b => (a -> b -> a) -> a -> Vector b -> a
526 {-# INLINE foldl' #-}
527 foldl' = G.foldl'
528
529 -- | Left fold on non-empty vectors with strict accumulator
530 foldl1' :: Prim a => (a -> a -> a) -> Vector a -> a
531 {-# INLINE foldl1' #-}
532 foldl1' = G.foldl1'
533
534 -- | Right fold
535 foldr :: Prim a => (a -> b -> b) -> b -> Vector a -> b
536 {-# INLINE foldr #-}
537 foldr = G.foldr
538
539 -- | Right fold on non-empty vectors
540 foldr1 :: Prim a => (a -> a -> a) -> Vector a -> a
541 {-# INLINE foldr1 #-}
542 foldr1 = G.foldr1
543
544 -- | Left fold (function applied to each element and its index)
545 ifoldl :: Prim b => (a -> Int -> b -> a) -> a -> Vector b -> a
546 {-# INLINE ifoldl #-}
547 ifoldl = G.ifoldl
548
549 -- | Left fold with strict accumulator (function applied to each element and
550 -- its index)
551 ifoldl' :: Prim b => (a -> Int -> b -> a) -> a -> Vector b -> a
552 {-# INLINE ifoldl' #-}
553 ifoldl' = G.ifoldl'
554
555 -- | Right fold (function applied to each element and its index)
556 ifoldr :: Prim a => (Int -> a -> b -> b) -> b -> Vector a -> b
557 {-# INLINE ifoldr #-}
558 ifoldr = G.ifoldr
559
560 -- Specialised folds
561 -- -----------------
562
563 all :: Prim a => (a -> Bool) -> Vector a -> Bool
564 {-# INLINE all #-}
565 all = G.all
566
567 any :: Prim a => (a -> Bool) -> Vector a -> Bool
568 {-# INLINE any #-}
569 any = G.any
570
571 sum :: (Prim a, Num a) => Vector a -> a
572 {-# INLINE sum #-}
573 sum = G.sum
574
575 product :: (Prim a, Num a) => Vector a -> a
576 {-# INLINE product #-}
577 product = G.product
578
579 maximum :: (Prim a, Ord a) => Vector a -> a
580 {-# INLINE maximum #-}
581 maximum = G.maximum
582
583 maximumBy :: Prim a => (a -> a -> Ordering) -> Vector a -> a
584 {-# INLINE maximumBy #-}
585 maximumBy = G.maximumBy
586
587 minimum :: (Prim a, Ord a) => Vector a -> a
588 {-# INLINE minimum #-}
589 minimum = G.minimum
590
591 minimumBy :: Prim a => (a -> a -> Ordering) -> Vector a -> a
592 {-# INLINE minimumBy #-}
593 minimumBy = G.minimumBy
594
595 maxIndex :: (Prim a, Ord a) => Vector a -> Int
596 {-# INLINE maxIndex #-}
597 maxIndex = G.maxIndex
598
599 maxIndexBy :: Prim a => (a -> a -> Ordering) -> Vector a -> Int
600 {-# INLINE maxIndexBy #-}
601 maxIndexBy = G.maxIndexBy
602
603 minIndex :: (Prim a, Ord a) => Vector a -> Int
604 {-# INLINE minIndex #-}
605 minIndex = G.minIndex
606
607 minIndexBy :: Prim a => (a -> a -> Ordering) -> Vector a -> Int
608 {-# INLINE minIndexBy #-}
609 minIndexBy = G.minIndexBy
610
611 -- Unfolding
612 -- ---------
613
614 unfoldr :: Prim a => (b -> Maybe (a, b)) -> b -> Vector a
615 {-# INLINE unfoldr #-}
616 unfoldr = G.unfoldr
617
618 -- Scans
619 -- -----
620
621 -- | Prefix scan
622 prescanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a
623 {-# INLINE prescanl #-}
624 prescanl = G.prescanl
625
626 -- | Prefix scan with strict accumulator
627 prescanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a
628 {-# INLINE prescanl' #-}
629 prescanl' = G.prescanl'
630
631 -- | Suffix scan
632 postscanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a
633 {-# INLINE postscanl #-}
634 postscanl = G.postscanl
635
636 -- | Suffix scan with strict accumulator
637 postscanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a
638 {-# INLINE postscanl' #-}
639 postscanl' = G.postscanl'
640
641 -- | Haskell-style scan
642 scanl :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a
643 {-# INLINE scanl #-}
644 scanl = G.scanl
645
646 -- | Haskell-style scan with strict accumulator
647 scanl' :: (Prim a, Prim b) => (a -> b -> a) -> a -> Vector b -> Vector a
648 {-# INLINE scanl' #-}
649 scanl' = G.scanl'
650
651 -- | Scan over a non-empty 'Vector'
652 scanl1 :: Prim a => (a -> a -> a) -> Vector a -> Vector a
653 {-# INLINE scanl1 #-}
654 scanl1 = G.scanl1
655
656 -- | Scan over a non-empty 'Vector' with a strict accumulator
657 scanl1' :: Prim a => (a -> a -> a) -> Vector a -> Vector a
658 {-# INLINE scanl1' #-}
659 scanl1' = G.scanl1'
660
661 -- Enumeration
662 -- -----------
663
664 enumFromTo :: (Prim a, Enum a) => a -> a -> Vector a
665 {-# INLINE enumFromTo #-}
666 enumFromTo = G.enumFromTo
667
668 enumFromThenTo :: (Prim a, Enum a) => a -> a -> a -> Vector a
669 {-# INLINE enumFromThenTo #-}
670 enumFromThenTo = G.enumFromThenTo
671
672 -- Conversion to/from lists
673 -- ------------------------
674
675 -- | Convert a vector to a list
676 toList :: Prim a => Vector a -> [a]
677 {-# INLINE toList #-}
678 toList = G.toList
679
680 -- | Convert a list to a vector
681 fromList :: Prim a => [a] -> Vector a
682 {-# INLINE fromList #-}
683 fromList = G.fromList
684