streams 0.2 → 0.3
raw patch · 4 files changed
+18/−2 lines, 4 filesdep ~comonad
Dependency ranges changed: comonad
Files
- Data/Stream/Branching.hs +5/−0
- Data/Stream/Infinite.hs +4/−0
- Data/Stream/Infinite/Skew.hs +7/−0
- streams.cabal +2/−2
Data/Stream/Branching.hs view
@@ -31,6 +31,7 @@ import Control.Monad import Data.Functor.Apply import Data.Stream.NonEmpty hiding (tail, tails, unfold, head, scanr, scanl)+import Data.Distributive import qualified Data.Stream.NonEmpty as NonEmpty #ifdef GHC_TYPEABLE@@ -41,6 +42,9 @@ data Stream f a = a :< f (Stream f a) +instance Distributive f => Distributive (Stream f) where+ distribute w = fmap head w :< fmap distribute (distribute (fmap tail w))+ head :: Stream f a -> a head (a :< _) = a {-# INLINE head #-}@@ -86,6 +90,7 @@ (f :< fs) <*> (a :< as) = f a :< ((<*>) <$> fs <*> as) (f :< fs) <* (_ :< as) = f :< ((<* ) <$> fs <*> as) (_ :< fs) *> (a :< as) = a :< (( *>) <$> fs <*> as)+ unfold :: Functor f => (b -> (a, f b)) -> b -> Stream f a unfold f c | (x, d) <- f c = x :< fmap (unfold f) d
Data/Stream/Infinite.hs view
@@ -84,6 +84,7 @@ import Data.Semigroup import Data.Foldable import Data.Traversable+import Data.Distributive import Data.Semigroup.Traversable import Data.Semigroup.Foldable import Data.Stream.NonEmpty (NonEmpty(..))@@ -104,6 +105,9 @@ instance Functor Stream where fmap = map b <$ _ = repeat b++instance Distributive Stream where+ distribute w = fmap head w :> distribute (fmap tail w) -- | Extract the first element of the sequence. head :: Stream a -> a
Data/Stream/Infinite/Skew.hs view
@@ -45,6 +45,7 @@ import Control.Applicative hiding (empty) import Control.Comonad import Control.Comonad.Apply+import Data.Distributive import Data.Functor.Alt import Data.Functor.Apply import Data.Foldable hiding (toList)@@ -105,6 +106,7 @@ data Stream a = !(Complete a) :< Stream a -- deriving Show + instance Show a => Show (Stream a) where showsPrec d as = showParen (d >= 10) $ showString "fromList " . showsPrec 11 (toList as)@@ -138,6 +140,7 @@ (q,0) -> as !! q (q,_) -> bs !! q + instance Foldable Stream where foldMap f (t :< ts) = foldMap f t `mappend` foldMap f ts foldr f z (t :< ts) = foldr f (foldr f z ts) t@@ -154,6 +157,9 @@ instance Traversable1 Stream where traverse1 f (t :< ts) = (:<) <$> traverse1 f t <.> traverse1 f ts +instance Distributive Stream where+ distribute w = tabulate (\i -> fmap (!! i) w)+ instance Semigroup (Stream a) where (<>) = (<!>) @@ -179,6 +185,7 @@ tabulate :: (Integer -> a) -> Stream a tabulate f = mapWithIndex (const . f) (pure ())+ indexed :: Stream a -> Stream (Integer, a) indexed = mapWithIndex (,)
streams.cabal view
@@ -1,6 +1,6 @@ name: streams category: Control, Comonads-version: 0.2+version: 0.3 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -74,7 +74,7 @@ library build-depends: base >= 4 && < 4.4,- comonad >= 0.6.0 && < 0.7,+ comonad >= 0.6.2.1 && < 0.7, functor-apply >= 0.7.4 && < 0.8, semigroups >= 0.3.2 && < 0.4