reverse (mutable only)
[darcs-mirrors/vector.git] / Data / Vector / MVector / Mut.hs
1 {-# LANGUAGE Rank2Types #-}
2
3 #include "phases.h"
4
5 module Data.Vector.MVector.Mut (
6 Mut(..), run, unstream, update, reverse, map
7 ) where
8
9 import qualified Data.Vector.MVector as MVector
10 import Data.Vector.MVector ( MVector )
11
12 import Data.Vector.Stream ( Stream )
13
14 import Prelude hiding ( reverse, map )
15
16 data Mut a = Mut (forall m mv. MVector mv m a => m (mv a))
17
18 run :: MVector mv m a => Mut a -> m (mv a)
19 {-# INLINE run #-}
20 run (Mut p) = p
21
22 trans :: Mut a -> (forall m mv. MVector mv m a => mv a -> m ()) -> Mut a
23 {-# INLINE trans #-}
24 trans (Mut p) q = Mut (do { v <- p; q v; return v })
25
26 unstream :: Stream a -> Mut a
27 {-# INLINE_STREAM unstream #-}
28 unstream s = Mut (MVector.unstream s)
29
30 update :: Mut a -> Stream (Int, a) -> Mut a
31 {-# INLINE_STREAM update #-}
32 update m s = trans m (\v -> MVector.update v s)
33
34 reverse :: Mut a -> Mut a
35 {-# INLINE_STREAM reverse #-}
36 reverse m = trans m (MVector.reverse)
37
38 map :: (a -> a) -> Mut a -> Mut a
39 {-# INLINE_STREAM map #-}
40 map f m = trans m (MVector.map f)
41