Replace asserts in Generic
[darcs-mirrors/vector.git] / Data / Vector / Generic.hs
1 {-# LANGUAGE Rank2Types, MultiParamTypeClasses, FlexibleContexts,
2 ScopedTypeVariables #-}
3 -- |
4 -- Module : Data.Vector.Generic
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 -- Generic interface to pure vectors
13 --
14
15 module Data.Vector.Generic (
16 -- * Immutable vectors
17 Vector(..),
18
19 -- * Length information
20 length, null,
21
22 -- * Construction
23 empty, singleton, cons, snoc, replicate, (++), copy,
24
25 -- * Accessing individual elements
26 (!), head, last, indexM, headM, lastM,
27 unsafeIndex, unsafeIndexM,
28
29 -- * Subvectors
30 slice, init, tail, take, drop,
31 unsafeSlice,
32
33 -- * Permutations
34 accum, (//), update, backpermute, reverse,
35
36 -- * Mapping
37 map, concatMap,
38
39 -- * Zipping and unzipping
40 zipWith, zipWith3, zip, zip3, unzip, unzip3,
41
42 -- * Comparisons
43 eq, cmp,
44
45 -- * Filtering
46 filter, takeWhile, dropWhile,
47
48 -- * Searching
49 elem, notElem, find, findIndex,
50
51 -- * Folding
52 foldl, foldl1, foldl', foldl1', foldr, foldr1,
53
54 -- * Specialised folds
55 and, or, sum, product, maximum, minimum,
56
57 -- * Unfolding
58 unfoldr,
59
60 -- * Scans
61 prescanl, prescanl',
62 postscanl, postscanl',
63 scanl, scanl', scanl1, scanl1',
64
65 -- * Enumeration
66 enumFromTo, enumFromThenTo,
67
68 -- * Conversion to/from lists
69 toList, fromList,
70
71 -- * Conversion to/from Streams
72 stream, unstream,
73
74 -- * MVector-based initialisation
75 new
76 ) where
77
78 import Data.Vector.Generic.Mutable ( MVector )
79
80 import qualified Data.Vector.Generic.New as New
81 import Data.Vector.Generic.New ( New )
82
83 import qualified Data.Vector.Fusion.Stream as Stream
84 import Data.Vector.Fusion.Stream ( Stream, MStream, inplace, inplace' )
85 import qualified Data.Vector.Fusion.Stream.Monadic as MStream
86 import Data.Vector.Fusion.Stream.Size
87 import Data.Vector.Fusion.Util
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,
96 elem, notElem,
97 foldl, foldl1, foldr, foldr1,
98 and, or, sum, product, maximum, minimum,
99 scanl, scanl1,
100 enumFromTo, enumFromThenTo )
101
102 #include "vector.h"
103
104 -- | Class of immutable vectors.
105 --
106 class Vector v a where
107 -- | Construct a pure vector from a monadic initialiser (not fusible!)
108 basicNew :: (forall mv m. MVector mv m a => m (mv a)) -> v a
109
110 -- | Length of the vector (not fusible!)
111 basicLength :: v a -> Int
112
113 -- | Yield a part of the vector without copying it. No range checks!
114 basicUnsafeSlice :: v a -> Int -> Int -> v a
115
116 -- | Yield the element at the given position in a monad. The monad allows us
117 -- to be strict in the vector if we want. Suppose we had
118 --
119 -- > unsafeIndex :: v a -> Int -> a
120 --
121 -- instead. Now, if we wanted to copy a vector, we'd do something like
122 --
123 -- > copy mv v ... = ... unsafeWrite mv i (unsafeIndex v i) ...
124 --
125 -- For lazy vectors, the indexing would not be evaluated which means that we
126 -- would retain a reference to the original vector in each element we write.
127 -- This is not what we want!
128 --
129 -- With 'basicUnsafeIndexM', we can do
130 --
131 -- > copy mv v ... = ... case basicUnsafeIndexM v i of
132 -- > Box x -> unsafeWrite mv i x ...
133 --
134 -- which does not have this problem because indexing (but not the returned
135 -- element!) is evaluated immediately.
136 --
137 basicUnsafeIndexM :: Monad m => v a -> Int -> m a
138
139 -- Fusion
140 -- ------
141
142 -- | Construct a pure vector from a monadic initialiser
143 new :: Vector v a => New a -> v a
144 {-# INLINE new #-}
145 new m = new' undefined m
146
147 -- | Same as 'new' but with a dummy argument necessary for correctly typing
148 -- the rule @uninplace@.
149 --
150 -- See http://hackage.haskell.org/trac/ghc/ticket/2600
151 new' :: Vector v a => v a -> New a -> v a
152 {-# INLINE_STREAM new' #-}
153 new' _ m = basicNew (New.run m)
154
155 -- | Convert a vector to a 'Stream'
156 stream :: Vector v a => v a -> Stream a
157 {-# INLINE_STREAM stream #-}
158 stream v = v `seq` (Stream.unfoldr get 0 `Stream.sized` Exact n)
159 where
160 n = length v
161
162 -- NOTE: the False case comes first in Core so making it the recursive one
163 -- makes the code easier to read
164 {-# INLINE get #-}
165 get i | i >= n = Nothing
166 | otherwise = case basicUnsafeIndexM v i of Box x -> Just (x, i+1)
167
168 -- | Create a vector from a 'Stream'
169 unstream :: Vector v a => Stream a -> v a
170 {-# INLINE unstream #-}
171 unstream s = new (New.unstream s)
172
173 {-# RULES
174
175 "stream/unstream [Vector]" forall v s.
176 stream (new' v (New.unstream s)) = s
177
178 "New.unstream/stream/new [Vector]" forall v p.
179 New.unstream (stream (new' v p)) = p
180
181 #-}
182
183 {-# RULES
184
185 "inplace [Vector]"
186 forall (f :: forall m. Monad m => MStream m a -> MStream m a) v m.
187 New.unstream (inplace f (stream (new' v m))) = New.transform f m
188
189 "uninplace [Vector]"
190 forall (f :: forall m. Monad m => MStream m a -> MStream m a) v m.
191 stream (new' v (New.transform f m)) = inplace f (stream (new' v m))
192
193 #-}
194
195 -- Length
196 -- ------
197
198 length :: Vector v a => v a -> Int
199 {-# INLINE_STREAM length #-}
200 length v = basicLength v
201
202 {-# RULES
203
204 "length/unstream [Vector]" forall v s.
205 length (new' v (New.unstream s)) = Stream.length s
206
207 #-}
208
209 null :: Vector v a => v a -> Bool
210 {-# INLINE null #-}
211 null v = length v == 0
212
213 -- Construction
214 -- ------------
215
216 -- | Empty vector
217 empty :: Vector v a => v a
218 {-# INLINE empty #-}
219 empty = unstream Stream.empty
220
221 -- | Vector with exaclty one element
222 singleton :: Vector v a => a -> v a
223 {-# INLINE singleton #-}
224 singleton x = unstream (Stream.singleton x)
225
226 -- | Vector of the given length with the given value in each position
227 replicate :: Vector v a => Int -> a -> v a
228 {-# INLINE replicate #-}
229 replicate n = unstream . Stream.replicate n
230
231 -- | Prepend an element
232 cons :: Vector v a => a -> v a -> v a
233 {-# INLINE cons #-}
234 cons x = unstream . Stream.cons x . stream
235
236 -- | Append an element
237 snoc :: Vector v a => v a -> a -> v a
238 {-# INLINE snoc #-}
239 snoc v = unstream . Stream.snoc (stream v)
240
241 infixr 5 ++
242 -- | Concatenate two vectors
243 (++) :: Vector v a => v a -> v a -> v a
244 {-# INLINE (++) #-}
245 v ++ w = unstream (stream v Stream.++ stream w)
246
247 -- | Create a copy of a vector. Useful when dealing with slices.
248 copy :: Vector v a => v a -> v a
249 {-# INLINE_STREAM copy #-}
250 copy = unstream . stream
251
252 {-# RULES
253
254 "copy/unstream [Vector]" forall v s.
255 copy (new' v (New.unstream s)) = new' v (New.unstream s)
256
257 #-}
258
259 -- Accessing individual elements
260 -- -----------------------------
261
262 -- | Indexing
263 (!) :: Vector v a => v a -> Int -> a
264 {-# INLINE_STREAM (!) #-}
265 v ! i = BOUNDS_CHECK(checkIndex) "(!)" i (length v)
266 $ unId (basicUnsafeIndexM v i)
267
268 -- | Unsafe indexing without bounds checking
269 unsafeIndex :: Vector v a => v a -> Int -> a
270 {-# INLINE_STREAM unsafeIndex #-}
271 unsafeIndex v i = unId (basicUnsafeIndexM v i)
272
273 -- | First element
274 head :: Vector v a => v a -> a
275 {-# INLINE_STREAM head #-}
276 head v = v ! 0
277
278 -- | Last element
279 last :: Vector v a => v a -> a
280 {-# INLINE_STREAM last #-}
281 last v = v ! (length v - 1)
282
283 {-# RULES
284
285 "(!)/unstream [Vector]" forall v i s.
286 new' v (New.unstream s) ! i = s Stream.!! i
287
288 "unsafeIndex/unstream [Vector]" forall v i s.
289 unsafeIndex (new' v (New.unstream s)) i = s Stream.!! i
290
291 "head/unstream [Vector]" forall v s.
292 head (new' v (New.unstream s)) = Stream.head s
293
294 "last/unstream [Vector]" forall v s.
295 last (new' v (New.unstream s)) = Stream.last s
296
297 #-}
298
299 -- | Monadic indexing which can be strict in the vector while remaining lazy in
300 -- the element.
301 indexM :: (Vector v a, Monad m) => v a -> Int -> m a
302 {-# INLINE_STREAM indexM #-}
303 indexM v i = BOUNDS_CHECK(checkIndex) "indexM" i (length v)
304 $ basicUnsafeIndexM v i
305
306 -- | Unsafe monadic indexing without bounds checks
307 unsafeIndexM :: (Vector v a, Monad m) => v a -> Int -> m a
308 {-# INLINE_STREAM unsafeIndexM #-}
309 unsafeIndexM v i = basicUnsafeIndexM v i
310
311 headM :: (Vector v a, Monad m) => v a -> m a
312 {-# INLINE_STREAM headM #-}
313 headM v = indexM v 0
314
315 lastM :: (Vector v a, Monad m) => v a -> m a
316 {-# INLINE_STREAM lastM #-}
317 lastM v = indexM v (length v - 1)
318
319 -- FIXME: the rhs of these rules are lazy in the stream which is WRONG
320 {- RULES
321
322 "indexM/unstream [Vector]" forall v i s.
323 indexM (new' v (New.unstream s)) i = return (s Stream.!! i)
324
325 "headM/unstream [Vector]" forall v s.
326 headM (new' v (New.unstream s)) = return (Stream.head s)
327
328 "lastM/unstream [Vector]" forall v s.
329 lastM (new' v (New.unstream s)) = return (Stream.last s)
330
331 -}
332
333 -- Subarrays
334 -- ---------
335
336 -- FIXME: slicing doesn't work with the inplace stuff at the moment
337
338 -- | Yield a part of the vector without copying it.
339 slice :: Vector v a => v a -> Int -- ^ starting index
340 -> Int -- ^ length
341 -> v a
342 {-# INLINE_STREAM slice #-}
343 slice v i n = BOUNDS_CHECK(checkSlice) "slice" i n (length v)
344 $ basicUnsafeSlice v i n
345
346 -- | Unsafely yield a part of the vector without copying it and without
347 -- performing bounds checks.
348 unsafeSlice :: Vector v a => v a -> Int -- ^ starting index
349 -> Int -- ^ length
350 -> v a
351 {-# INLINE_STREAM unsafeSlice #-}
352 unsafeSlice v i n = basicUnsafeSlice v i n
353
354 -- | Yield all but the last element without copying.
355 init :: Vector v a => v a -> v a
356 {-# INLINE_STREAM init #-}
357 init v = slice v 0 (length v - 1)
358
359 -- | All but the first element (without copying).
360 tail :: Vector v a => v a -> v a
361 {-# INLINE_STREAM tail #-}
362 tail v = slice v 1 (length v - 1)
363
364 -- | Yield the first @n@ elements without copying.
365 take :: Vector v a => Int -> v a -> v a
366 {-# INLINE_STREAM take #-}
367 take n v = slice v 0 (min n' (length v))
368 where n' = max n 0
369
370 -- | Yield all but the first @n@ elements without copying.
371 drop :: Vector v a => Int -> v a -> v a
372 {-# INLINE_STREAM drop #-}
373 drop n v = slice v (min n' len) (max 0 (len - n'))
374 where n' = max n 0
375 len = length v
376
377 {-# RULES
378
379 "slice/new [Vector]" forall v p i n.
380 slice (new' v p) i n = new' v (New.slice p i n)
381
382 "unsafeSlice/new [Vector]" forall v p i n.
383 unsafeSlice (new' v p) i n = new' v (New.unsafeSlice p i n)
384
385 "init/new [Vector]" forall v p.
386 init (new' v p) = new' v (New.init p)
387
388 "tail/new [Vector]" forall v p.
389 tail (new' v p) = new' v (New.tail p)
390
391 "take/new [Vector]" forall n v p.
392 take n (new' v p) = new' v (New.take n p)
393
394 "drop/new [Vector]" forall n v p.
395 drop n (new' v p) = new' v (New.drop n p)
396
397 #-}
398
399 -- Permutations
400 -- ------------
401
402 accum :: Vector v a => (a -> b -> a) -> v a -> [(Int,b)] -> v a
403 {-# INLINE accum #-}
404 accum f v us = new (New.accum f (New.unstream (stream v))
405 (Stream.fromList us))
406
407 (//) :: Vector v a => v a -> [(Int, a)] -> v a
408 {-# INLINE (//) #-}
409 v // us = new (New.update (New.unstream (stream v))
410 (Stream.fromList us))
411
412 update :: (Vector v a, Vector v (Int, a)) => v a -> v (Int, a) -> v a
413 {-# INLINE update #-}
414 update v w = new (New.update (New.unstream (stream v)) (stream w))
415
416 -- This somewhat non-intuitive definition ensures that the resulting vector
417 -- does not retain references to the original one even if it is lazy in its
418 -- elements. This would not be the case if we simply used
419 --
420 -- backpermute v is = map (v!) is
421 backpermute :: (Vector v a, Vector v Int) => v a -> v Int -> v a
422 {-# INLINE backpermute #-}
423 backpermute v is = seq v
424 $ unstream
425 $ Stream.unbox
426 $ Stream.map (indexM v)
427 $ stream is
428
429 reverse :: (Vector v a) => v a -> v a
430 {-# INLINE reverse #-}
431 reverse = new . New.reverse . New.unstream . stream
432
433 -- Mapping
434 -- -------
435
436 -- | Map a function over a vector
437 map :: (Vector v a, Vector v b) => (a -> b) -> v a -> v b
438 {-# INLINE map #-}
439 map f = unstream . inplace' (MStream.map f) . stream
440
441 concatMap :: (Vector v a, Vector v b) => (a -> v b) -> v a -> v b
442 {-# INLINE concatMap #-}
443 concatMap f = unstream . Stream.concatMap (stream . f) . stream
444
445 -- Zipping/unzipping
446 -- -----------------
447
448 -- | Zip two vectors with the given function.
449 zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> v a -> v b -> v c
450 {-# INLINE zipWith #-}
451 zipWith f xs ys = unstream (Stream.zipWith f (stream xs) (stream ys))
452
453 -- | Zip three vectors with the given function.
454 zipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (a -> b -> c -> d) -> v a -> v b -> v c -> v d
455 {-# INLINE zipWith3 #-}
456 zipWith3 f xs ys zs = unstream (Stream.zipWith3 f (stream xs) (stream ys) (stream zs))
457
458 zip :: (Vector v a, Vector v b, Vector v (a,b)) => v a -> v b -> v (a, b)
459 {-# INLINE zip #-}
460 zip = zipWith (,)
461
462 zip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => v a -> v b -> v c -> v (a, b, c)
463 {-# INLINE zip3 #-}
464 zip3 = zipWith3 (,,)
465
466 unzip :: (Vector v a, Vector v b, Vector v (a,b)) => v (a, b) -> (v a, v b)
467 {-# INLINE unzip #-}
468 unzip xs = (map fst xs, map snd xs)
469
470 unzip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => v (a, b, c) -> (v a, v b, v c)
471 {-# INLINE unzip3 #-}
472 unzip3 xs = (map (\(a, b, c) -> a) xs, map (\(a, b, c) -> b) xs, map (\(a, b, c) -> c) xs)
473
474 -- Comparisons
475 -- -----------
476
477 eq :: (Vector v a, Eq a) => v a -> v a -> Bool
478 {-# INLINE eq #-}
479 xs `eq` ys = stream xs == stream ys
480
481 cmp :: (Vector v a, Ord a) => v a -> v a -> Ordering
482 {-# INLINE cmp #-}
483 cmp xs ys = compare (stream xs) (stream ys)
484
485 -- Filtering
486 -- ---------
487
488 -- | Drop elements which do not satisfy the predicate
489 filter :: Vector v a => (a -> Bool) -> v a -> v a
490 {-# INLINE filter #-}
491 filter f = unstream . inplace (MStream.filter f) . stream
492
493 -- | Yield the longest prefix of elements satisfying the predicate.
494 takeWhile :: Vector v a => (a -> Bool) -> v a -> v a
495 {-# INLINE takeWhile #-}
496 takeWhile f = unstream . Stream.takeWhile f . stream
497
498 -- | Drop the longest prefix of elements that satisfy the predicate.
499 dropWhile :: Vector v a => (a -> Bool) -> v a -> v a
500 {-# INLINE dropWhile #-}
501 dropWhile f = unstream . Stream.dropWhile f . stream
502
503 -- Searching
504 -- ---------
505
506 infix 4 `elem`
507 -- | Check whether the vector contains an element
508 elem :: (Vector v a, Eq a) => a -> v a -> Bool
509 {-# INLINE elem #-}
510 elem x = Stream.elem x . stream
511
512 infix 4 `notElem`
513 -- | Inverse of `elem`
514 notElem :: (Vector v a, Eq a) => a -> v a -> Bool
515 {-# INLINE notElem #-}
516 notElem x = Stream.notElem x . stream
517
518 -- | Yield 'Just' the first element matching the predicate or 'Nothing' if no
519 -- such element exists.
520 find :: Vector v a => (a -> Bool) -> v a -> Maybe a
521 {-# INLINE find #-}
522 find f = Stream.find f . stream
523
524 -- | Yield 'Just' the index of the first element matching the predicate or
525 -- 'Nothing' if no such element exists.
526 findIndex :: Vector v a => (a -> Bool) -> v a -> Maybe Int
527 {-# INLINE findIndex #-}
528 findIndex f = Stream.findIndex f . stream
529
530 -- Folding
531 -- -------
532
533 -- | Left fold
534 foldl :: Vector v b => (a -> b -> a) -> a -> v b -> a
535 {-# INLINE foldl #-}
536 foldl f z = Stream.foldl f z . stream
537
538 -- | Lefgt fold on non-empty vectors
539 foldl1 :: Vector v a => (a -> a -> a) -> v a -> a
540 {-# INLINE foldl1 #-}
541 foldl1 f = Stream.foldl1 f . stream
542
543 -- | Left fold with strict accumulator
544 foldl' :: Vector v b => (a -> b -> a) -> a -> v b -> a
545 {-# INLINE foldl' #-}
546 foldl' f z = Stream.foldl' f z . stream
547
548 -- | Left fold on non-empty vectors with strict accumulator
549 foldl1' :: Vector v a => (a -> a -> a) -> v a -> a
550 {-# INLINE foldl1' #-}
551 foldl1' f = Stream.foldl1' f . stream
552
553 -- | Right fold
554 foldr :: Vector v a => (a -> b -> b) -> b -> v a -> b
555 {-# INLINE foldr #-}
556 foldr f z = Stream.foldr f z . stream
557
558 -- | Right fold on non-empty vectors
559 foldr1 :: Vector v a => (a -> a -> a) -> v a -> a
560 {-# INLINE foldr1 #-}
561 foldr1 f = Stream.foldr1 f . stream
562
563 -- Specialised folds
564 -- -----------------
565
566 and :: Vector v Bool => v Bool -> Bool
567 {-# INLINE and #-}
568 and = Stream.and . stream
569
570 or :: Vector v Bool => v Bool -> Bool
571 {-# INLINE or #-}
572 or = Stream.or . stream
573
574 sum :: (Vector v a, Num a) => v a -> a
575 {-# INLINE sum #-}
576 sum = Stream.foldl' (+) 0 . stream
577
578 product :: (Vector v a, Num a) => v a -> a
579 {-# INLINE product #-}
580 product = Stream.foldl' (*) 1 . stream
581
582 maximum :: (Vector v a, Ord a) => v a -> a
583 {-# INLINE maximum #-}
584 maximum = Stream.foldl1' max . stream
585
586 minimum :: (Vector v a, Ord a) => v a -> a
587 {-# INLINE minimum #-}
588 minimum = Stream.foldl1' min . stream
589
590 -- Unfolding
591 -- ---------
592
593 unfoldr :: Vector v a => (b -> Maybe (a, b)) -> b -> v a
594 {-# INLINE unfoldr #-}
595 unfoldr f = unstream . Stream.unfoldr f
596
597 -- Scans
598 -- -----
599
600 -- | Prefix scan
601 prescanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a
602 {-# INLINE prescanl #-}
603 prescanl f z = unstream . inplace' (MStream.prescanl f z) . stream
604
605 -- | Prefix scan with strict accumulator
606 prescanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a
607 {-# INLINE prescanl' #-}
608 prescanl' f z = unstream . inplace' (MStream.prescanl' f z) . stream
609
610 -- | Suffix scan
611 postscanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a
612 {-# INLINE postscanl #-}
613 postscanl f z = unstream . inplace' (MStream.postscanl f z) . stream
614
615 -- | Suffix scan with strict accumulator
616 postscanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a
617 {-# INLINE postscanl' #-}
618 postscanl' f z = unstream . inplace' (MStream.postscanl' f z) . stream
619
620 -- | Haskell-style scan
621 scanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a
622 {-# INLINE scanl #-}
623 scanl f z = unstream . Stream.scanl f z . stream
624
625 -- | Haskell-style scan with strict accumulator
626 scanl' :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a
627 {-# INLINE scanl' #-}
628 scanl' f z = unstream . Stream.scanl' f z . stream
629
630 -- | Scan over a non-empty vector
631 scanl1 :: Vector v a => (a -> a -> a) -> v a -> v a
632 {-# INLINE scanl1 #-}
633 scanl1 f = unstream . inplace (MStream.scanl1 f) . stream
634
635 -- | Scan over a non-empty vector with a strict accumulator
636 scanl1' :: Vector v a => (a -> a -> a) -> v a -> v a
637 {-# INLINE scanl1' #-}
638 scanl1' f = unstream . inplace (MStream.scanl1' f) . stream
639
640 -- Enumeration
641 -- -----------
642
643 -- FIXME: The Enum class is irreparably broken, there just doesn't seem to be a
644 -- way to implement this generically. Either specialise this or define a new
645 -- Enum-like class with a proper interface.
646
647 enumFromTo :: (Vector v a, Enum a) => a -> a -> v a
648 {-# INLINE enumFromTo #-}
649 enumFromTo x y = unstream (Stream.enumFromTo x y)
650
651 enumFromThenTo :: (Vector v a, Enum a) => a -> a -> a -> v a
652 {-# INLINE enumFromThenTo #-}
653 enumFromThenTo from next to = fromList [from, next .. to]
654
655 -- | Convert a vector to a list
656 toList :: Vector v a => v a -> [a]
657 {-# INLINE toList #-}
658 toList = Stream.toList . stream
659
660 -- | Convert a list to a vector
661 fromList :: Vector v a => [a] -> v a
662 {-# INLINE fromList #-}
663 fromList = unstream . Stream.fromList
664