0918e3c93270bab7ba6c4df2931f177eac07210c
[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
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 data Mut a = Mut (forall m mv. MVector mv m a => m (mv a))
15
16 run :: MVector mv m a => Mut a -> m (mv a)
17 {-# INLINE run #-}
18 run (Mut p) = p
19
20 unstream :: Stream a -> Mut a
21 {-# INLINE_STREAM unstream #-}
22 unstream s = Mut (MVector.unstream s)
23
24 update :: Mut a -> Stream (Int, a) -> Mut a
25 {-# INLINE_STREAM update #-}
26 update (Mut p) s = Mut (do { v <- p; MVector.update v s; return v })
27