Stream 0.1.1 → 0.2
raw patch · 2 files changed
+29/−13 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Stream: (<:>) :: a -> Stream a -> Stream a
+ Data.Stream: inits :: Stream a -> Stream ([a])
+ Data.Stream: tails :: Stream a -> Stream (Stream a)
Files
- Data/Stream.hs +28/−12
- Stream.cabal +1/−1
Data/Stream.hs view
@@ -6,8 +6,11 @@ -- * The type of streams Stream(..) -- * Basic functions+ , (<:>) , head , tail+ , inits+ , tails -- * Stream transformations , map , intersperse @@ -55,6 +58,8 @@ -- | An infinite sequence. data Stream a = Cons a (Stream a) deriving (Show, Eq) +infixr 5 `Cons`+ instance Functor Stream where fmap f (Cons x xs) = Cons (f x) (fmap f xs) @@ -66,6 +71,12 @@ return = repeat (Cons x xs) >>= f = Cons (head (f x)) (tail (xs >>= f)) +infixr 5 <:>+-- | The @ \<:\> @ operator is an infix version of the 'Cons'+-- constructor.+(<:>) :: a -> Stream a -> Stream a+(<:>) = Cons+ -- | Extract the first element of the sequence. head :: Stream a -> a head (Cons x _ ) = x@@ -97,19 +108,21 @@ iterate :: (a -> a) -> a -> Stream a iterate f x = Cons x (iterate f (f x)) --- | 'take' @n@ @xs@ returns the first @n@ elements of--- @xs@. +-- | 'take' @n@ @xs@ returns the first @n@ elements of @xs@. -- --- /Beware/: passing a negative integer as the first argument will cause an error.+-- /Beware/: passing a negative integer as the first argument will+-- cause an error. take :: Int -> Stream a -> [a] take n (Cons x xs) | n == 0 = [] | n > 0 = x : (take (n - 1) xs) | otherwise = error "Stream.take: negative argument." --- | 'drop' @n@ @xs@ drops the first @n@ elements off the front of the sequence @xs@.+-- | 'drop' @n@ @xs@ drops the first @n@ elements off the front of+-- the sequence @xs@. -- --- /Beware/: passing a negative integer as the first argument will cause an error.+-- /Beware/: passing a negative integer as the first argument will+-- cause an error. drop :: Int -> Stream a -> Stream a drop n xs | n == 0 = xs@@ -123,16 +136,18 @@ | p x = x : takeWhile p xs | otherwise = [] --- | 'dropWhile' @p@ @xs@ returns the suffix remaining after 'takeWhile' @p@ @xs@.+-- | 'dropWhile' @p@ @xs@ returns the suffix remaining after+-- 'takeWhile' @p@ @xs@. ----- /Beware/: this function may diverge if every element of @xs@ satisfies @p@, e.g.--- @dropWhile even (repeat 0)@ will loop.+-- /Beware/: this function may diverge if every element of @xs@+-- satisfies @p@, e.g. @dropWhile even (repeat 0)@ will loop. dropWhile :: (a -> Bool) -> Stream a -> Stream a dropWhile p (Cons x xs) | p x = dropWhile p xs | otherwise = Cons x xs --- | 'repeat' @x@ returns a constant stream, where all elements are equal to @x@.+-- | 'repeat' @x@ returns a constant stream, where all elements are+-- equal to @x@. repeat :: a -> Stream a repeat x = Cons x (repeat x) @@ -162,7 +177,8 @@ | n > 0 = (!!) (n - 1) xs | otherwise = error "Stream.!! negative argument" --- | The 'zip' function takes two streams and returns a list of corresponding pairs.+-- | The 'zip' function takes two streams and returns a list of+-- corresponding pairs. zip :: Stream a -> Stream b -> Stream (a,b) zip (Cons x xs) (Cons y ys) = Cons (x,y) (zip xs ys) @@ -189,8 +205,8 @@ break :: (a -> Bool) -> Stream a -> ([a], Stream a) break p = span (not . p) --- | The 'words' function breaks a stream of characters into a stream of words,--- which were delimited by white space.+-- | The 'words' function breaks a stream of characters into a+-- stream of words, which were delimited by white space. -- -- /Beware/: if the stream of characters @xs@ does not contain white -- space, accessing the tail of @words xs@ will loop.
Stream.cabal view
@@ -1,5 +1,5 @@ Name: Stream-Version: 0.1.1+Version: 0.2 License: BSD3 License-file: LICENSE Author: Wouter Swierstra