packages feed

comonad-transformers 0.1.1 → 0.2.0

raw patch · 8 files changed

+70/−7 lines, 8 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Control.Comonad.Hoist.Class: class ComonadHoist t
+ Control.Comonad.Hoist.Class: cohoist :: (ComonadHoist t, Comonad w) => t w a -> t Identity a
+ Control.Comonad.Hoist.Class: instance ComonadHoist IdentityT
+ Control.Comonad.Trans.Env: instance ComonadHoist (EnvT e)
+ Control.Comonad.Trans.Store: instance ComonadHoist (StoreT s)
+ Control.Comonad.Trans.Stream: instance Functor f => ComonadHoist (StreamT f)
+ Control.Comonad.Trans.Traced: censor :: Functor w => (m -> m) -> TracedT m w a -> TracedT m w a
+ Control.Comonad.Trans.Traced: instance Monoid m => ComonadHoist (TracedT m)
+ Control.Comonad.Trans.Traced: listen :: Functor w => TracedT m w a -> TracedT m w (a, m)
+ Control.Comonad.Trans.Traced: listens :: Functor w => (m -> b) -> TracedT m w a -> TracedT m w (a, b)

Files

+ Control/Comonad/Hoist/Class.hs view
@@ -0,0 +1,28 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Comonad.Hoist.Class+-- Copyright   :  (C) 2008-2011 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+--+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  portable+----------------------------------------------------------------------------+module Control.Comonad.Hoist.Class (ComonadHoist(..)) where++import Control.Comonad+import Control.Monad.Trans.Identity+import Data.Functor.Identity++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.+  --+  -- 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++instance ComonadHoist IdentityT where+  cohoist = IdentityT . Identity . extract . runIdentityT
Control/Comonad/Trans/Class.hs view
@@ -14,7 +14,7 @@ import Control.Monad.Trans.Identity  class ComonadTrans t where-  lower :: Comonad w => t w a -> w a +  lower   :: Comonad w => t w a -> w a   -- avoiding orphans instance ComonadTrans IdentityT where
Control/Comonad/Trans/Env.hs view
@@ -24,6 +24,7 @@  import Control.Comonad import Control.Comonad.Trans.Class+import Control.Comonad.Hoist.Class import Data.Functor.Identity  type Env e = EnvT e Identity@@ -47,6 +48,9 @@  instance ComonadTrans (EnvT e) where   lower (EnvT _ wa) = wa++instance ComonadHoist (EnvT e) where+  cohoist (EnvT e wa) = EnvT e (Identity (extract wa))  ask :: EnvT e w a -> e ask (EnvT e _) = e
Control/Comonad/Trans/Identity.hs view
@@ -22,8 +22,13 @@   extend f (IdentityT m) = IdentityT (extend (f . IdentityT) m) -} --- Provided by Control.Comonad.Trans.Class to avoid an orphan+-- Provided by Control.Comonad.Trans.Class to avoid orphans {- instance ComonadTrans IdentityT where-  colift = IdentityT+  lower = IdentityT+-}++{-+instance ComonadHoist IdentityT where+  cohoist = IdentityT . Identity . extract . runIdentityT -}
Control/Comonad/Trans/Store.hs view
@@ -31,6 +31,7 @@   ) where  import Control.Comonad+import Control.Comonad.Hoist.Class import Control.Comonad.Trans.Class import Data.Functor.Identity @@ -57,6 +58,9 @@  instance ComonadTrans (StoreT s) where   lower (StoreT f s) = fmap ($s) f++instance ComonadHoist (StoreT s) where+  cohoist (StoreT f s) = StoreT (Identity (extract f)) s  get :: StoreT s w a -> s get (StoreT _ s) = s
Control/Comonad/Trans/Stream.hs view
@@ -27,6 +27,7 @@  import Control.Applicative import Control.Comonad+import Control.Comonad.Hoist.Class import Control.Comonad.Trans.Class import Data.Functor.Identity import Data.Foldable@@ -41,6 +42,9 @@ runStream :: Stream f a -> (a, f (Stream f a)) runStream = runIdentity . runStreamT +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)+ data StreamT f w a = StreamT { runStreamT :: w (a, f (StreamT f w a)) }  instance (Functor w, Functor f) => Functor (StreamT f w) where@@ -54,6 +58,10 @@ instance Functor f => ComonadTrans (StreamT f) where   lower = fmap fst . runStreamT +instance Functor f => ComonadHoist (StreamT f) where+  cohoist (StreamT wa) = stream a (cohoist <$> as) where+    (a,as) = extract wa + instance (Foldable w, Foldable f) => Foldable (StreamT f w) where   foldMap f = foldMap (\(a, as) -> f a `mappend` foldMap (foldMap f) as) . runStreamT @@ -62,9 +70,6 @@  tails :: Comonad w => StreamT f w a -> f (StreamT f w a) tails = snd . extract . runStreamT--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)  unfoldsW :: (Comonad w, Functor f) => (w a -> (b, f a)) -> w a -> StreamT f w b unfoldsW f = StreamT . extend (\s -> let (h, t) = f s in (h, fmap (\a -> unfoldsW f (a <$ s)) t))
Control/Comonad/Trans/Traced.hs view
@@ -21,9 +21,13 @@   , TracedT(..)   -- * Operations   , trace+  , listen+  , listens+  , censor   ) where  import Control.Comonad+import Control.Comonad.Hoist.Class import Control.Comonad.Trans.Class import Data.Functor.Identity import Data.Monoid@@ -48,5 +52,17 @@ instance Monoid m => ComonadTrans (TracedT m) where   lower = fmap ($mempty) . runTracedT +instance Monoid m => ComonadHoist (TracedT m) where+  cohoist = traced . extract . runTracedT+ trace :: (Comonad w, Monoid m) => m -> TracedT m w a -> a trace m (TracedT wf) = extract wf m++listen :: Functor w => TracedT m w a -> TracedT m w (a, m)+listen = TracedT . fmap (\f m -> (f m, m)) . runTracedT++listens :: Functor w => (m -> b) -> TracedT m w a -> TracedT m w (a, b)+listens g = TracedT . fmap (\f m -> (f m, g m)) . runTracedT ++censor :: Functor w => (m -> m) -> TracedT m w a -> TracedT m w a+censor g = TracedT . fmap (. g) . runTracedT
comonad-transformers.cabal view
@@ -1,6 +1,6 @@ name:          comonad-transformers category:      Control, Comonads-version:       0.1.1+version:       0.2.0 license:       BSD3 cabal-version: >= 1.2 license-file:  LICENSE@@ -22,6 +22,7 @@     transformers >= 0.2.0 && <= 0.3    exposed-modules:+    Control.Comonad.Hoist.Class     Control.Comonad.Trans.Class     Control.Comonad.Trans.Discont     Control.Comonad.Trans.Env