1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
{-# LANGUAGE TypeOperators #-}
module Util where
import Control.Monad
import Control.Monad.ST
import Data.Word
import Data.Int
import qualified Data.ByteString as B
import qualified Data.Vector as V
import Data.Vector.Mutable hiding (length)
import Test.QuickCheck
mfromList :: [e] -> ST s (MVector s e)
mfromList l = do v <- new (length l)
fill l 0 v
where
fill [] _ v = return v
fill (x:xs) i v = do write v i x
fill xs (i+1) v
instance (Arbitrary e) => Arbitrary (V.Vector e) where
arbitrary = fmap V.fromList arbitrary
instance Arbitrary B.ByteString where
arbitrary = B.pack `fmap` arbitrary
|