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