free-5.0.1: Monads for free

Copyright(C) 2008-2013 Edward Kmett
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
PortabilityMPTCs, fundeps
Safe HaskellSafe
LanguageHaskell2010

Control.Comonad.Trans.Cofree

Description

The cofree comonad transformer

Synopsis

Documentation

newtype CofreeT f w a Source #

This is a cofree comonad of some functor f, with a comonad w threaded through it at each level.

Constructors

CofreeT 

Fields

Instances

(Functor f, ComonadEnv e w) => ComonadEnv e (CofreeT f w) Source # 

Methods

ask :: CofreeT f w a -> e #

(Functor f, Comonad w) => ComonadCofree f (CofreeT f w) Source # 

Methods

unwrap :: CofreeT f w a -> f (CofreeT f w a) Source #

ComonadTrans (CofreeT f) Source # 

Methods

lower :: Comonad w => CofreeT f w a -> w a #

Functor f => ComonadHoist (CofreeT f) Source # 

Methods

cohoist :: (Comonad w, Comonad v) => (forall x. w x -> v x) -> CofreeT f w a -> CofreeT f v a #

Alternative f => MonadTrans (CofreeT f) Source # 

Methods

lift :: Monad m => m a -> CofreeT f m a #

(Alternative f, Monad w) => Monad (CofreeT f w) Source # 

Methods

(>>=) :: CofreeT f w a -> (a -> CofreeT f w b) -> CofreeT f w b #

(>>) :: CofreeT f w a -> CofreeT f w b -> CofreeT f w b #

return :: a -> CofreeT f w a #

fail :: String -> CofreeT f w a #

(Functor f, Functor w) => Functor (CofreeT f w) Source # 

Methods

fmap :: (a -> b) -> CofreeT f w a -> CofreeT f w b #

(<$) :: a -> CofreeT f w b -> CofreeT f w a #

(Alternative f, Applicative w) => Applicative (CofreeT f w) Source # 

Methods

pure :: a -> CofreeT f w a #

(<*>) :: CofreeT f w (a -> b) -> CofreeT f w a -> CofreeT f w b #

liftA2 :: (a -> b -> c) -> CofreeT f w a -> CofreeT f w b -> CofreeT f w c #

(*>) :: CofreeT f w a -> CofreeT f w b -> CofreeT f w b #

(<*) :: CofreeT f w a -> CofreeT f w b -> CofreeT f w a #

(Foldable f, Foldable w) => Foldable (CofreeT f w) Source # 

Methods

fold :: Monoid m => CofreeT f w m -> m #

foldMap :: Monoid m => (a -> m) -> CofreeT f w a -> m #

foldr :: (a -> b -> b) -> b -> CofreeT f w a -> b #

foldr' :: (a -> b -> b) -> b -> CofreeT f w a -> b #

foldl :: (b -> a -> b) -> b -> CofreeT f w a -> b #

foldl' :: (b -> a -> b) -> b -> CofreeT f w a -> b #

foldr1 :: (a -> a -> a) -> CofreeT f w a -> a #

foldl1 :: (a -> a -> a) -> CofreeT f w a -> a #

toList :: CofreeT f w a -> [a] #

null :: CofreeT f w a -> Bool #

length :: CofreeT f w a -> Int #

elem :: Eq a => a -> CofreeT f w a -> Bool #

maximum :: Ord a => CofreeT f w a -> a #

minimum :: Ord a => CofreeT f w a -> a #

sum :: Num a => CofreeT f w a -> a #

product :: Num a => CofreeT f w a -> a #

(Traversable f, Traversable w) => Traversable (CofreeT f w) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> CofreeT f w a -> f (CofreeT f w b) #

sequenceA :: Applicative f => CofreeT f w (f a) -> f (CofreeT f w a) #

mapM :: Monad m => (a -> m b) -> CofreeT f w a -> m (CofreeT f w b) #

sequence :: Monad m => CofreeT f w (m a) -> m (CofreeT f w a) #

(Alternative f, MonadZip f, MonadZip m) => MonadZip (CofreeT f m) Source # 

Methods

mzip :: CofreeT f m a -> CofreeT f m b -> CofreeT f m (a, b) #

mzipWith :: (a -> b -> c) -> CofreeT f m a -> CofreeT f m b -> CofreeT f m c #

munzip :: CofreeT f m (a, b) -> (CofreeT f m a, CofreeT f m b) #

(Functor f, Comonad w) => Comonad (CofreeT f w) Source # 

Methods

extract :: CofreeT f w a -> a #

duplicate :: CofreeT f w a -> CofreeT f w (CofreeT f w a) #

extend :: (CofreeT f w a -> b) -> CofreeT f w a -> CofreeT f w b #

Eq (w (CofreeF f a (CofreeT f w a))) => Eq (CofreeT f w a) Source # 

Methods

(==) :: CofreeT f w a -> CofreeT f w a -> Bool #

(/=) :: CofreeT f w a -> CofreeT f w a -> Bool #

(Typeable (* -> *) f, Typeable (* -> *) w, Typeable * a, Data (w (CofreeF f a (CofreeT f w a))), Data a) => Data (CofreeT f w a) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CofreeT f w a -> c (CofreeT f w a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (CofreeT f w a) #

toConstr :: CofreeT f w a -> Constr #

dataTypeOf :: CofreeT f w a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (CofreeT f w a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CofreeT f w a)) #

gmapT :: (forall b. Data b => b -> b) -> CofreeT f w a -> CofreeT f w a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CofreeT f w a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CofreeT f w a -> r #

gmapQ :: (forall d. Data d => d -> u) -> CofreeT f w a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> CofreeT f w a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> CofreeT f w a -> m (CofreeT f w a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CofreeT f w a -> m (CofreeT f w a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CofreeT f w a -> m (CofreeT f w a) #

Ord (w (CofreeF f a (CofreeT f w a))) => Ord (CofreeT f w a) Source # 

Methods

compare :: CofreeT f w a -> CofreeT f w a -> Ordering #

(<) :: CofreeT f w a -> CofreeT f w a -> Bool #

(<=) :: CofreeT f w a -> CofreeT f w a -> Bool #

(>) :: CofreeT f w a -> CofreeT f w a -> Bool #

(>=) :: CofreeT f w a -> CofreeT f w a -> Bool #

max :: CofreeT f w a -> CofreeT f w a -> CofreeT f w a #

min :: CofreeT f w a -> CofreeT f w a -> CofreeT f w a #

Read (w (CofreeF f a (CofreeT f w a))) => Read (CofreeT f w a) Source # 

Methods

readsPrec :: Int -> ReadS (CofreeT f w a) #

readList :: ReadS [CofreeT f w a] #

readPrec :: ReadPrec (CofreeT f w a) #

readListPrec :: ReadPrec [CofreeT f w a] #

Show (w (CofreeF f a (CofreeT f w a))) => Show (CofreeT f w a) Source # 

Methods

showsPrec :: Int -> CofreeT f w a -> ShowS #

show :: CofreeT f w a -> String #

showList :: [CofreeT f w a] -> ShowS #

type Cofree f = CofreeT f Identity Source #

The cofree Comonad of a functor f.

cofree :: CofreeF f a (Cofree f a) -> Cofree f a Source #

Wrap another layer around a cofree comonad value.

cofree is a right inverse of runCofree.

runCofree . cofree == id

runCofree :: Cofree f a -> CofreeF f a (Cofree f a) Source #

Unpeel the first layer off a cofree comonad value.

runCofree is a right inverse of cofree.

cofree . runCofree == id

data CofreeF f a b Source #

This is the base functor of the cofree comonad transformer.

Constructors

a :< (f b) infixr 5 

Instances

Traversable f => Bitraversable (CofreeF f) Source # 

Methods

bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> CofreeF f a b -> f (CofreeF f c d) #

Foldable f => Bifoldable (CofreeF f) Source # 

Methods

bifold :: Monoid m => CofreeF f m m -> m #

bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> CofreeF f a b -> m #

bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> CofreeF f a b -> c #

bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> CofreeF f a b -> c #

Functor f => Bifunctor (CofreeF f) Source # 

Methods

bimap :: (a -> b) -> (c -> d) -> CofreeF f a c -> CofreeF f b d #

first :: (a -> b) -> CofreeF f a c -> CofreeF f b c #

second :: (b -> c) -> CofreeF f a b -> CofreeF f a c #

Functor f => Functor (CofreeF f a) Source # 

Methods

fmap :: (a -> b) -> CofreeF f a a -> CofreeF f a b #

(<$) :: a -> CofreeF f a b -> CofreeF f a a #

Foldable f => Foldable (CofreeF f a) Source # 

Methods

fold :: Monoid m => CofreeF f a m -> m #

foldMap :: Monoid m => (a -> m) -> CofreeF f a a -> m #

foldr :: (a -> b -> b) -> b -> CofreeF f a a -> b #

foldr' :: (a -> b -> b) -> b -> CofreeF f a a -> b #

foldl :: (b -> a -> b) -> b -> CofreeF f a a -> b #

foldl' :: (b -> a -> b) -> b -> CofreeF f a a -> b #

foldr1 :: (a -> a -> a) -> CofreeF f a a -> a #

foldl1 :: (a -> a -> a) -> CofreeF f a a -> a #

toList :: CofreeF f a a -> [a] #

null :: CofreeF f a a -> Bool #

length :: CofreeF f a a -> Int #

elem :: Eq a => a -> CofreeF f a a -> Bool #

maximum :: Ord a => CofreeF f a a -> a #

minimum :: Ord a => CofreeF f a a -> a #

sum :: Num a => CofreeF f a a -> a #

product :: Num a => CofreeF f a a -> a #

Traversable f => Traversable (CofreeF f a) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> CofreeF f a a -> f (CofreeF f a b) #

sequenceA :: Applicative f => CofreeF f a (f a) -> f (CofreeF f a a) #

mapM :: Monad m => (a -> m b) -> CofreeF f a a -> m (CofreeF f a b) #

sequence :: Monad m => CofreeF f a (m a) -> m (CofreeF f a a) #

(Eq (f b), Eq a) => Eq (CofreeF f a b) Source # 

Methods

(==) :: CofreeF f a b -> CofreeF f a b -> Bool #

(/=) :: CofreeF f a b -> CofreeF f a b -> Bool #

(Typeable (* -> *) f, Typeable * a, Typeable * b, Data a, Data (f b), Data b) => Data (CofreeF f a b) Source # 

Methods

gfoldl :: (forall d c. Data d => c (d -> c) -> d -> c c) -> (forall g. g -> c g) -> CofreeF f a b -> c (CofreeF f a b) #

gunfold :: (forall c r. Data c => c (c -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (CofreeF f a b) #

toConstr :: CofreeF f a b -> Constr #

dataTypeOf :: CofreeF f a b -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (CofreeF f a b)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CofreeF f a b)) #

gmapT :: (forall c. Data c => c -> c) -> CofreeF f a b -> CofreeF f a b #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CofreeF f a b -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CofreeF f a b -> r #

gmapQ :: (forall d. Data d => d -> u) -> CofreeF f a b -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> CofreeF f a b -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> CofreeF f a b -> m (CofreeF f a b) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CofreeF f a b -> m (CofreeF f a b) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CofreeF f a b -> m (CofreeF f a b) #

(Ord (f b), Ord a) => Ord (CofreeF f a b) Source # 

Methods

compare :: CofreeF f a b -> CofreeF f a b -> Ordering #

(<) :: CofreeF f a b -> CofreeF f a b -> Bool #

(<=) :: CofreeF f a b -> CofreeF f a b -> Bool #

(>) :: CofreeF f a b -> CofreeF f a b -> Bool #

(>=) :: CofreeF f a b -> CofreeF f a b -> Bool #

max :: CofreeF f a b -> CofreeF f a b -> CofreeF f a b #

min :: CofreeF f a b -> CofreeF f a b -> CofreeF f a b #

(Read (f b), Read a) => Read (CofreeF f a b) Source # 

Methods

readsPrec :: Int -> ReadS (CofreeF f a b) #

readList :: ReadS [CofreeF f a b] #

readPrec :: ReadPrec (CofreeF f a b) #

readListPrec :: ReadPrec [CofreeF f a b] #

(Show (f b), Show a) => Show (CofreeF f a b) Source # 

Methods

showsPrec :: Int -> CofreeF f a b -> ShowS #

show :: CofreeF f a b -> String #

showList :: [CofreeF f a b] -> ShowS #

class (Functor f, Comonad w) => ComonadCofree f w | w -> f where Source #

Allows you to peel a layer off a cofree comonad.

Minimal complete definition

unwrap

Methods

unwrap :: w a -> f (w a) Source #

Remove a layer.

Instances

ComonadCofree [] Tree Source # 

Methods

unwrap :: Tree a -> [Tree a] Source #

ComonadCofree Maybe NonEmpty Source # 

Methods

unwrap :: NonEmpty a -> Maybe (NonEmpty a) Source #

Functor f => ComonadCofree f (Cofree f) Source # 

Methods

unwrap :: Cofree f a -> f (Cofree f a) Source #

Comonad w => ComonadCofree Identity (CoiterT w) Source # 

Methods

unwrap :: CoiterT w a -> Identity (CoiterT w a) Source #

(ComonadCofree f w, Monoid m) => ComonadCofree f (TracedT m w) Source # 

Methods

unwrap :: TracedT m w a -> f (TracedT m w a) Source #

ComonadCofree f w => ComonadCofree f (StoreT s w) Source # 

Methods

unwrap :: StoreT s w a -> f (StoreT s w a) Source #

ComonadCofree f w => ComonadCofree f (EnvT e w) Source # 

Methods

unwrap :: EnvT e w a -> f (EnvT e w a) Source #

ComonadCofree f w => ComonadCofree f (IdentityT * w) Source # 

Methods

unwrap :: IdentityT * w a -> f (IdentityT * w a) Source #

(Functor f, Comonad w) => ComonadCofree f (CofreeT f w) Source # 

Methods

unwrap :: CofreeT f w a -> f (CofreeT f w a) Source #

ComonadCofree (Const * b) ((,) b) Source # 

Methods

unwrap :: (b, a) -> Const * b (b, a) Source #

headF :: CofreeF f a b -> a Source #

Extract the head of the base functor

tailF :: CofreeF f a b -> f b Source #

Extract the tails of the base functor

transCofreeT :: (Functor g, Comonad w) => (forall x. f x -> g x) -> CofreeT f w a -> CofreeT g w a Source #

Lift a natural transformation from f to g into a comonad homomorphism from CofreeT f w to CofreeT g w

coiterT :: (Functor f, Comonad w) => (w a -> f (w a)) -> w a -> CofreeT f w a Source #

Unfold a CofreeT comonad transformer from a coalgebra and an initial comonad.