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