comonad-transformers 0.3 → 0.4
raw patch · 6 files changed
+54/−7 lines, 6 filesdep ~comonadPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: comonad
API changes (from Hackage documentation)
+ Control.Comonad.Trans.Env.Lazy: instance (Monoid e, ComonadApply w) => ComonadApply (EnvT e w)
+ Control.Comonad.Trans.Env.Lazy: instance (Monoid e, FunctorApply w) => FunctorApply (EnvT e w)
+ Control.Comonad.Trans.Env.Strict: instance (Monoid e, ComonadApply w) => ComonadApply (EnvT e w)
+ Control.Comonad.Trans.Env.Strict: instance (Monoid e, FunctorApply w) => FunctorApply (EnvT e w)
+ Control.Comonad.Trans.Stream: instance (ComonadApply w, FunctorApply f) => ComonadApply (StreamT f w)
+ Control.Comonad.Trans.Stream: instance (ComonadApply w, FunctorApply f) => FunctorApply (StreamT f w)
+ Control.Comonad.Trans.Traced: instance (Monoid m, ComonadApply w) => ComonadApply (TracedT m w)
+ Control.Comonad.Trans.Traced: instance (Monoid m, FunctorApply w) => FunctorApply (TracedT m w)
Files
- Control/Comonad/Hoist/Class.hs +4/−3
- Control/Comonad/Trans/Env/Lazy.hs +6/−0
- Control/Comonad/Trans/Env/Strict.hs +6/−0
- Control/Comonad/Trans/Stream.hs +30/−2
- Control/Comonad/Trans/Traced.hs +6/−0
- comonad-transformers.cabal +2/−2
Control/Comonad/Hoist/Class.hs view
@@ -16,10 +16,11 @@ class ComonadHoist t where -- | Ideally we would offer a way to lift comonad homomorphisms- -- but this isn't Haskell 98, so we settle for the most common case.+ -- but this isn't Haskell 98, so we settle for the most common case+ -- here. --- -- liftTrans :: (forall a. w a -> v a) -> t w a -> t v a - -- cohoist = liftTrans (Identity . extract)+ -- > liftTrans :: (forall a. w a -> v a) -> t w a -> t v a + -- > cohoist = liftTrans (Identity . extract) cohoist :: Comonad w => t w a -> t Identity a -- avoiding orphans
Control/Comonad/Trans/Env/Lazy.hs view
@@ -32,6 +32,7 @@ import Control.Comonad.Trans.Class import Control.Comonad.Hoist.Class import Data.Functor.Identity+import Data.Monoid type Env e = EnvT e Identity data EnvT e w a = EnvT e (w a)@@ -51,6 +52,11 @@ instance Comonad w => Comonad (EnvT e w) where extract ~(EnvT _ wa) = extract wa duplicate p@(~(EnvT e wa)) = EnvT e (p <$ wa)++instance (Monoid e, FunctorApply w) => FunctorApply (EnvT e w) where+ ~(EnvT ef wf) <.> ~(EnvT ea wa) = EnvT (ef `mappend` ea) (wf <.> wa)++instance (Monoid e, ComonadApply w) => ComonadApply (EnvT e w) instance ComonadTrans (EnvT e) where lower ~(EnvT _ wa) = wa
Control/Comonad/Trans/Env/Strict.hs view
@@ -32,6 +32,7 @@ import Control.Comonad.Trans.Class import Control.Comonad.Hoist.Class import Data.Functor.Identity+import Data.Monoid type Env e = EnvT e Identity data EnvT e w a = EnvT e (w a)@@ -57,6 +58,11 @@ instance ComonadHoist (EnvT e) where cohoist (EnvT e wa) = EnvT e (Identity (extract wa))++instance (Monoid e, FunctorApply w) => FunctorApply (EnvT e w) where+ EnvT ef wf <.> EnvT ea wa = EnvT (ef `mappend` ea) (wf <.> wa)++instance (Monoid e, ComonadApply w) => ComonadApply (EnvT e w) ask :: EnvT e w a -> e ask (EnvT e _) = e
Control/Comonad/Trans/Stream.hs view
@@ -1,3 +1,4 @@+-- {-# LANGUAGE FlexibleContexts, UndecidableInstances #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Comonad.Trans.Stream@@ -16,12 +17,14 @@ module Control.Comonad.Trans.Stream ( -- * The Stream comonad- Stream, stream, runStream+ Stream+ , stream+ , runStream+ , unfolds -- * The Stream comonad transformer , StreamT(..) -- * Operations , tails- , unfolds , unfoldsW ) where @@ -34,17 +37,26 @@ import Data.Monoid import Data.Traversable +-- | Isomorphic to the definition:+--+-- > data Stream f a = a :< f (Stream f a) type Stream f = StreamT f Identity +-- | cons onto an f-branching stream stream :: a -> f (Stream f a) -> Stream f a stream a as = StreamT (Identity (a, as)) +-- | uncons from an f-branching stream runStream :: Stream f a -> (a, f (Stream f a)) runStream = runIdentity . runStreamT +-- | unfold a stream from a seed. unfolds :: Functor f => (a -> (b, f a)) -> a -> Stream f b unfolds f a = let (h, t) = f a in stream h (unfolds f <$> t) +-- | The f-branching stream comonad transformer is a comonadic version of+-- the \"ListT done Right\" monad transformer. You can extract the underlying comonadic +-- value by using 'lower' or runStream data StreamT f w a = StreamT { runStreamT :: w (a, f (StreamT f w a)) } instance (Functor w, Functor f) => Functor (StreamT f w) where@@ -55,6 +67,12 @@ duplicate = StreamT . extend (\w -> (StreamT w, duplicate <$> snd (extract w))) . runStreamT extend f = StreamT . extend (\w -> (f (StreamT w), extend f <$> snd (extract w))) . runStreamT +instance (ComonadApply w, FunctorApply f) => FunctorApply (StreamT f w) where+ StreamT ffs <.> StreamT aas = StreamT (liftW2 wfa ffs aas) where+ wfa (f,fs) (a,as) = (f a, (<.>) <$> fs <.> as)++instance (ComonadApply w, FunctorApply f) => ComonadApply (StreamT f w)+ instance Functor f => ComonadTrans (StreamT f) where lower = fmap fst . runStreamT @@ -67,6 +85,16 @@ instance (Traversable w, Traversable f) => Traversable (StreamT f w) where traverse f (StreamT w) = StreamT <$> traverse (\(a, as) -> (,) <$> f a <*> traverse (traverse f) as) w++{-+instance Show a => Show (Identity a) where+ showsPrec d (Identity a) = showParen (d > 10) $+ showString "Identity " . showsPrec 11 a++instance (Show (w (a, f (StreamT f w a)))) => Show (StreamT f w a) where+ showsPrec d (StreamT w) = showParen (d > 10) $ + showString "StreamT " . showsPrec 11 w+-} tails :: Comonad w => StreamT f w a -> f (StreamT f w a) tails = snd . extract . runStreamT
Control/Comonad/Trans/Traced.hs view
@@ -29,6 +29,7 @@ import Control.Comonad import Control.Comonad.Hoist.Class import Control.Comonad.Trans.Class+import Data.Functor import Data.Functor.Identity import Data.Monoid @@ -54,6 +55,11 @@ instance Monoid m => ComonadHoist (TracedT m) where cohoist = traced . extract . runTracedT++instance (Monoid m, FunctorApply w) => FunctorApply (TracedT m w) where+ TracedT wf <.> TracedT wa = TracedT ((\mf ma m -> (mf m) (ma m)) <$> wf <.> wa)++instance (Monoid m, ComonadApply w) => ComonadApply (TracedT m w) trace :: (Comonad w, Monoid m) => m -> TracedT m w a -> a trace m (TracedT wf) = extract wf m
comonad-transformers.cabal view
@@ -1,6 +1,6 @@ name: comonad-transformers category: Control, Comonads-version: 0.3+version: 0.4 license: BSD3 cabal-version: >= 1.2 license-file: LICENSE@@ -18,7 +18,7 @@ build-depends: base >= 4 && < 4.4, array >= 0.3.0.1 && < 0.4,- comonad >= 0.3 && < 0.4,+ comonad >= 0.4 && < 0.5, transformers >= 0.2.0 && <= 0.3 exposed-modules: