diff options
Diffstat (limited to 'lib/Data')
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index 2900149..652b980 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs | |||
@@ -36,7 +36,6 @@ import Foreign.C.String | |||
36 | import Foreign.C.Types(CInt,CChar) | 36 | import Foreign.C.Types(CInt,CChar) |
37 | import Data.Complex | 37 | import Data.Complex |
38 | import Control.Monad(when) | 38 | import Control.Monad(when) |
39 | import Control.Monad.Trans | ||
40 | 39 | ||
41 | #if __GLASGOW_HASKELL__ >= 605 | 40 | #if __GLASGOW_HASKELL__ >= 605 |
42 | import GHC.ForeignPtr (mallocPlainForeignPtrBytes) | 41 | import GHC.ForeignPtr (mallocPlainForeignPtrBytes) |
@@ -362,33 +361,33 @@ foldVectorG f s0 v = foldLoop g s0 (dim v) | |||
362 | ------------------------------------------------------------------- | 361 | ------------------------------------------------------------------- |
363 | 362 | ||
364 | -- | monadic map over Vectors | 363 | -- | monadic map over Vectors |
365 | mapVectorM :: (Storable a, Storable b, MonadIO m) => (a -> m b) -> Vector a -> m (Vector b) | 364 | mapVectorM :: (Storable a, Storable b, Monad m) => (a -> m b) -> Vector a -> m (Vector b) |
366 | mapVectorM f v = do | 365 | mapVectorM f v = do |
367 | w <- liftIO $ createVector (dim v) | 366 | w <- return $! unsafePerformIO $! createVector (dim v) |
368 | mapVectorM' f v w 0 (dim v -1) | 367 | mapVectorM' f v w 0 (dim v -1) |
369 | return w | 368 | return w |
370 | where mapVectorM' f' v' w' !k !t | 369 | where mapVectorM' f' v' w' !k !t |
371 | | k == t = do | 370 | | k == t = do |
372 | x <- liftIO $ unsafeWith v' $ \p -> peekElemOff p k | 371 | x <- return $! inlinePerformIO $! unsafeWith v' $! \p -> peekElemOff p k |
373 | y <- f' x | 372 | y <- f' x |
374 | liftIO $ unsafeWith w' $ \q -> pokeElemOff q k y | 373 | return $! inlinePerformIO $! unsafeWith w' $! \q -> pokeElemOff q k y |
375 | | otherwise = do | 374 | | otherwise = do |
376 | x <- liftIO $ unsafeWith v' $ \p -> peekElemOff p k | 375 | x <- return $! inlinePerformIO $! unsafeWith v' $! \p -> peekElemOff p k |
377 | y <- f' x | 376 | y <- f' x |
378 | liftIO $ unsafeWith w' $ \q -> pokeElemOff q k y | 377 | _ <- return $! inlinePerformIO $! unsafeWith w' $! \q -> pokeElemOff q k y |
379 | mapVectorM' f' v' w' (k+1) t | 378 | mapVectorM' f' v' w' (k+1) t |
380 | {-# INLINE mapVectorM #-} | 379 | {-# INLINE mapVectorM #-} |
381 | 380 | ||
382 | -- | monadic map over Vectors | 381 | -- | monadic map over Vectors |
383 | mapVectorM_ :: (Storable a, MonadIO m) => (a -> m ()) -> Vector a -> m () | 382 | mapVectorM_ :: (Storable a, Monad m) => (a -> m ()) -> Vector a -> m () |
384 | mapVectorM_ f v = do | 383 | mapVectorM_ f v = do |
385 | mapVectorM' f v 0 (dim v -1) | 384 | mapVectorM' f v 0 (dim v -1) |
386 | where mapVectorM' f' v' !k !t | 385 | where mapVectorM' f' v' !k !t |
387 | | k == t = do | 386 | | k == t = do |
388 | x <- liftIO $ unsafeWith v' $ \p -> peekElemOff p k | 387 | x <- return $! inlinePerformIO $! unsafeWith v' $! \p -> peekElemOff p k |
389 | f' x | 388 | f' x |
390 | | otherwise = do | 389 | | otherwise = do |
391 | x <- liftIO $ unsafeWith v' $ \p -> peekElemOff p k | 390 | x <- return $! inlinePerformIO $! unsafeWith v' $! \p -> peekElemOff p k |
392 | _ <- f' x | 391 | _ <- f' x |
393 | mapVectorM' f' v' (k+1) t | 392 | mapVectorM' f' v' (k+1) t |
394 | {-# INLINE mapVectorM_ #-} | 393 | {-# INLINE mapVectorM_ #-} |