packages feed

streams 0.3.1 → 0.4

raw patch · 8 files changed

+51/−35 lines, 8 filesdep ~comonaddep ~functor-applydep ~semigroups

Dependency ranges changed: comonad, functor-apply, semigroups

Files

Data/Stream/Branching.hs view
@@ -73,24 +73,25 @@   fmap f (a :< as) = f a :< fmap (fmap f) as   b <$ (_ :< as) = b :< fmap (b <$) as -instance Functor f => Comonad (Stream f) where-  extract (a :< _) = a+instance Functor f => Extend (Stream f) where   extend f w = f w :< fmap (extend f) (tail w)   duplicate w = w :< fmap duplicate (tail w) -instance FunctorApply f => FunctorApply (Stream f) where+instance Functor f => Comonad (Stream f) where+  extract (a :< _) = a++instance Apply f => Apply (Stream f) where   (f :< fs) <.> (a :< as) = f a :< ((<.>) <$> fs <.> as)   (f :< fs) <.  (_ :< as) = f :< ((<. ) <$> fs <.> as)   (_ :< fs)  .> (a :< as) = a :< (( .>) <$> fs <.> as) -instance FunctorApply f => ComonadApply (Stream f)+instance Apply f => ComonadApply (Stream f)  instance Applicative f => Applicative (Stream f) where   pure a = as where as = a :< pure as   (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/Future.hs view
@@ -107,13 +107,15 @@   traverse1 f (Last a)  = Last <$> f a   traverse1 f (a :< as) = (:<) <$> f a <.> traverse1 f as -instance Comonad Future where-  extract = head+instance Extend Future where   duplicate = tails   extend f w@(_ :< as) = f w :< extend f as   extend f w@(Last _)  = Last (f w) -instance FunctorApply Future where+instance Comonad Future where+  extract = head++instance Apply Future where   Last f    <.> Last a    = Last (f a)   (f :< _)  <.> Last a    = Last (f a)   Last f    <.> (a :< _ ) = Last (f a)@@ -127,7 +129,7 @@   Last _     .> (b :< _) = Last b   (_ :< as)  .> (b :< bs) = b :< (as .> bs)   -instance FunctorAlt Future where+instance Alt Future where   Last a    <!> bs = a :< bs   (a :< as) <!> bs = a :< (as <!> bs) 
Data/Stream/Future/Skew.hs view
@@ -71,11 +71,13 @@   fmap f (Tip a) = Tip (f a)   fmap f (Bin w a l r) = Bin w (f a) (fmap f l) (fmap f r) +instance Extend Complete where+  extend f w@Tip {} = Tip (f w)+  extend f w@(Bin n _ l r) = Bin n (f w) (extend f l) (extend f r)+ instance Comonad Complete where   extract (Tip a) = a   extract (Bin _ a _ _) = a-  extend f w@Tip {} = Tip (f w)-  extend f w@(Bin n _ l r) = Bin n (f w) (extend f l) (extend f r)  instance Foldable Complete where   foldMap f (Tip a) = f a @@ -120,16 +122,18 @@   fmap f (t :< ts) = fmap f t :< fmap f ts   fmap f (Last t) = Last (fmap f t) -instance Comonad Future where-  extract = head+instance Extend Future where   extend g (Last t)  = Last (extendTree g t Last)   extend g (t :< ts) = extendTree g t (:< ts) :< extend g ts +instance Comonad Future where+  extract = head+ extendTree :: (Future a -> b) -> Complete a -> (Complete a -> Future a) -> Complete b extendTree g w@Tip{}         f = Tip (g (f w)) extendTree g w@(Bin n _ l r) f = Bin n (g (f w)) (extendTree g l (:< f r))  (extendTree g r f) -instance FunctorApply Future where+instance Apply Future where   Last (Tip f)         <.> as                   = singleton (f (extract as))   fs                   <.> Last (Tip a)         = singleton (extract fs a)   Last (Bin _ f lf rf) <.> Last (Bin _ a la ra) = f a <| (lf :< Last rf  <.> la :< Last ra )@@ -148,7 +152,7 @@   pure = repeat   (<*>) = (<.>) -instance FunctorAlt Future where+instance Alt Future where   as <!> bs = foldr (<|) bs as  instance Foldable Future where
Data/Stream/Infinite.hs view
@@ -124,12 +124,14 @@ tails :: Stream a -> Stream (Stream a) tails w = w :> tails (tail w) -instance Comonad Stream where-  extract = head+instance Extend Stream where   duplicate = tails   extend f w = f w :> extend f (tail w) -instance FunctorApply Stream where+instance Comonad Stream where+  extract = head++instance Apply Stream where   (f :> fs) <.> (a :> as) = f a :> (fs <.> as)   as        <.  _         = as   _          .> bs        = bs
Data/Stream/Infinite/Functional/Zipper.hs view
@@ -98,11 +98,13 @@ uncons :: Zipper a -> (a, Zipper a) uncons (n :~ f) = (f n, n + 1 :~ f) +instance Extend Zipper where+  duplicate (n :~ f) = n :~ (:~ f)+ instance Comonad Zipper where   extract (n :~ f) = f n-  duplicate (n :~ f) = n :~ (:~ f) -instance FunctorApply Zipper where+instance Apply Zipper where   (nf :~ f) <.> (na :~ a)      | dn <- na - nf     = nf :~ \n -> f n (a (n + dn))
Data/Stream/Infinite/Skew.hs view
@@ -68,11 +68,13 @@   fmap f (Tip a) = Tip (f a)   fmap f (Bin w a l r) = Bin w (f a) (fmap f l) (fmap f r) +instance Extend Complete where+  extend f w@Tip {} = Tip (f w)+  extend f w@(Bin n _ l r) = Bin n (f w) (extend f l) (extend f r)+ instance Comonad Complete where   extract (Tip a) = a   extract (Bin _ a _ _) = a-  extend f w@Tip {} = Tip (f w)-  extend f w@(Bin n _ l r) = Bin n (f w) (extend f l) (extend f r)  instance Foldable Complete where   foldMap f (Tip a) = f a @@ -106,7 +108,6 @@ 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)@@ -114,15 +115,17 @@ instance Functor Stream where   fmap f (t :< ts) = fmap f t :< fmap f ts -instance Comonad Stream where-  extract = head+instance Extend Stream where   extend g0 (t :< ts) = go g0 t (:< ts) :< extend g0 ts     where        go :: (Stream a -> b) -> Complete a -> (Complete a -> Stream a) -> Complete b       go g w@Tip{}         f = Tip (g (f w))       go g w@(Bin n _ l r) f = Bin n (g (f w)) (go g l (:< f r))  (go g r f) -instance FunctorApply Stream where+instance Comonad Stream where+  extract = head++instance Apply Stream where   fs <.> as = mapWithIndex (\n f -> f (as !! n)) fs   as <.  _  = as   _   .> bs = bs@@ -135,7 +138,7 @@   (<* ) = (<. )   ( *>) = ( .>) -instance FunctorAlt Stream where+instance Alt Stream where   as <!> bs = tabulate $ \i -> case quotRem i 2 of      (q,0) -> as !! q     (q,_) -> bs !! q
Data/Stream/NonEmpty.hs view
@@ -133,16 +133,18 @@   fmap f ~(a :| as) = f a :| fmap f as   b <$ ~(_ :| as)   = b   :| (b <$ as) -instance Comonad NonEmpty where-  extract ~(a :| _) = a+instance Extend NonEmpty where   extend f w@ ~(_ :| aas) = f w :| case aas of       []     -> []       (a:as) -> toList (extend f (a :| as))++instance Comonad NonEmpty where+  extract ~(a :| _) = a   -instance FunctorApply NonEmpty where+instance Apply NonEmpty where   (<.>) = ap -instance FunctorAlt NonEmpty where+instance Alt NonEmpty where   (a :| as) <!> ~(b :| bs) = a :| (as ++ b : bs)  instance ComonadApply NonEmpty
streams.cabal view
@@ -1,6 +1,6 @@ name:          streams category:      Control, Comonads-version:       0.3.1+version:       0.4 license:       BSD3 cabal-version: >= 1.6 license-file:  LICENSE@@ -74,10 +74,10 @@ library   build-depends:     base >= 4 && < 4.4,-    comonad >= 0.7 && < 0.8,+    comonad >= 0.9 && < 0.10,+    functor-apply >= 0.9 && < 0.10,     distributive >= 0.1 && < 0.2,-    functor-apply >= 0.7.4.1 && < 0.8,-    semigroups >= 0.3.2 && < 0.4+    semigroups >= 0.3.4 && < 0.4    extensions: CPP   if impl(ghc)