module Data.Vector.Mutable.IO ( Vector(..) )
where
import Data.Vector.MVector ( MVector(..), MVectorPure(..) )
import qualified Data.Vector.Mutable.ST as STV
import GHC.Base ( RealWorld )
import GHC.ST ( ST(..) )
import GHC.IOBase ( IO(..) )
import Prelude hiding ( length )
newtype Vector a = Vector (STV.Vector RealWorld a)
instance MVectorPure Vector a where
length (Vector v) = length v
unsafeSlice (Vector v) j m = Vector (unsafeSlice v j m)
overlaps (Vector v1) (Vector v2) = overlaps v1 v2
instance MVector Vector IO a where
unsafeNew n = Vector `fmap` stToIO (unsafeNew n)
unsafeNewWith n x = Vector `fmap` stToIO (unsafeNewWith n x)
unsafeRead (Vector v) i = stToIO (unsafeRead v i)
unsafeWrite (Vector v) i x = stToIO (unsafeWrite v i x)
clear (Vector v) = stToIO (clear v)
stToIO :: ST RealWorld a -> IO a
stToIO (ST m) = IO m