From 82ef9ddfba8b36d85981ea5606bf886c240c83c6 Mon Sep 17 00:00:00 2001 From: Roman Leshchinskiy Date: Sun, 6 Jul 2008 17:00:04 +0000 Subject: [PATCH] Use new Stream functions --- Data/Vector.hs | 14 +++++++------- Data/Vector/Unboxed.hs | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Data/Vector.hs b/Data/Vector.hs index dc6faac..9b0bfb9 100644 --- a/Data/Vector.hs +++ b/Data/Vector.hs @@ -9,7 +9,7 @@ import qualified Data.Vector.Prim as Prim import qualified Data.Vector.Mutable as Mut import qualified Data.Vector.Stream as Stream -import Data.Vector.Stream ( Step(..), Stream(..) ) +import Data.Vector.Stream ( Stream ) import Control.Exception ( assert ) import Control.Monad.ST ( ST, runST ) @@ -44,20 +44,20 @@ new' n x init = runST ( stream :: Vector a -> Stream a {-# INLINE_STREAM stream #-} -stream (Vector i n arr) = Stream get i n +stream (Vector i n arr) = Stream.unfold get i n where n' = n+i {-# INLINE get #-} - get j | j < n' = Prim.at' arr j \$ \x -> Yield x (j+1) - | otherwise = Done + get j | j < n' = Prim.at' arr j \$ \x -> Just (x, j+1) + | otherwise = Nothing unstream :: Stream a -> Vector a {-# INLINE_STREAM unstream #-} -unstream s@(Stream _ _ n) = new n (\mv -> +unstream s = new (Stream.bound s) (\mv -> do - n' <- Mut.fill mv s - return \$ Mut.slice mv 0 n' + n <- Mut.fill mv s + return \$ Mut.slice mv 0 n ) {-# RULES diff --git a/Data/Vector/Unboxed.hs b/Data/Vector/Unboxed.hs index 015a397..7daef6a 100644 --- a/Data/Vector/Unboxed.hs +++ b/Data/Vector/Unboxed.hs @@ -10,7 +10,7 @@ import qualified Data.Vector.Unboxed.Mutable as Mut import Data.Vector.Unboxed.Unbox ( Unbox ) import qualified Data.Vector.Stream as Stream -import Data.Vector.Stream ( Step(..), Stream(..) ) +import Data.Vector.Stream ( Stream ) import Control.Exception ( assert ) import Control.Monad.ST ( ST, runST ) @@ -35,20 +35,20 @@ new n init = runST ( stream :: Unbox a => Vector a -> Stream a {-# INLINE_STREAM stream #-} -stream (Vector i n arr) = Stream get i n +stream (Vector i n arr) = Stream.unfold get i n where n' = n+i {-# INLINE get #-} - get j | j < n' = Yield (Prim.at arr j) (j+1) - | otherwise = Done + get j | j < n' = Just (Prim.at arr j, j+1) + | otherwise = Nothing unstream :: Unbox a => Stream a -> Vector a {-# INLINE_STREAM unstream #-} -unstream s@(Stream _ _ n) = new n (\mv -> +unstream s = new (Stream.bound s) (\mv -> do - n' <- Mut.fill mv s - return \$ Mut.slice mv 0 n' + n <- Mut.fill mv s + return \$ Mut.slice mv 0 n ) {-# RULES -- 1.9.1