free-4.12.4: Monads for free

Copyright | (C) 2008-2013 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | MPTCs, fundeps
Safe Haskell | Safe
Language | Haskell2010

Control.Comonad.Trans.Cofree

Description

The cofree comonad transformer

Synopsis

- newtype CofreeT f w a = CofreeT {
  - runCofreeT :: w (CofreeF f a (CofreeT f w a))
  }
- type Cofree f = CofreeT f Identity
- cofree :: CofreeF f a (Cofree f a) -> Cofree f a
- runCofree :: Cofree f a -> CofreeF f a (Cofree f a)
- data CofreeF f a b = a :< (f b)
- class (Functor f, Comonad w) => ComonadCofree f w | w -> f where
- headF :: CofreeF f a b -> a
- tailF :: CofreeF f a b -> f b
- transCofreeT :: (Functor g, Comonad w) => (forall x. f x -> g x) -> CofreeT f w a -> CofreeT g w a
- coiterT :: (Functor f, Comonad w) => (w a -> f (w a)) -> w a -> CofreeT f w a

# Documentation

newtype CofreeT f w a #

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

Constructors

CofreeT |
Fields runCofreeT :: w (CofreeF f a (CofreeT f w a))

Instances

(Functor f, ComonadEnv e w) => ComonadEnv e (CofreeT f w) # |
Methods ask :: CofreeT f w a -> e #
(Functor f, Comonad w) => ComonadCofree f (CofreeT f w) # |
Methods unwrap :: CofreeT f w a -> f (CofreeT f w a) #
Functor f => ComonadHoist (CofreeT f) # |
Methods cohoist :: (Comonad w, Comonad v) => (forall x. w x -> v x) -> CofreeT f w a -> CofreeT f v a #
ComonadTrans (CofreeT f) # |
Methods lower :: Comonad w => CofreeT f w a -> w a #
Alternative f => MonadTrans (CofreeT f) # |
Methods lift :: Monad m => m a -> CofreeT f m a #
(Alternative f, Monad w) => Monad (CofreeT f w) # |
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) # |
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) # |
Methods pure :: a -> CofreeT f w a # (<*>) :: CofreeT f w (a -> b) -> CofreeT f w a -> CofreeT f w b # (*>) :: 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) # |
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) # |
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) # |
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) # |
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) # |
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) # |
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) # |
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) # |
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) # |
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 #

The cofree `Comonad` of a functor `f`.

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

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) #

Unpeel the first layer off a cofree comonad value.

`runCofree` is a right inverse of `cofree`.

    cofree . runCofree == id

data CofreeF f a b #

This is the base functor of the cofree comonad transformer.

Constructors

a :< (f b) infixr 5 |

Instances

Functor f => Bifunctor (CofreeF f) # |
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 #
Traversable f => Bitraversable (CofreeF f) # |
Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> CofreeF f a b -> f (CofreeF f c d) #
Foldable f => Bifoldable (CofreeF f) # |
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 => Functor (CofreeF f a) # |
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) # |
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) # |
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 a, Eq (f b)) => Eq (CofreeF f a b) # |
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) # |
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 a, Ord (f b)) => Ord (CofreeF f a b) # |
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 a, Read (f b)) => Read (CofreeF f a b) # |
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 a, Show (f b)) => Show (CofreeF f a b) # |
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 #

Allows you to peel a layer off a cofree comonad.

Minimal complete definition

unwrap

Methods

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

Remove a layer.

Instances

ComonadCofree [] Tree # |
Methods unwrap :: Tree a -> [Tree a] #
ComonadCofree Maybe NonEmpty # |
Methods unwrap :: NonEmpty a -> Maybe (NonEmpty a) #
Functor f => ComonadCofree f (Cofree f) # |
Methods unwrap :: Cofree f a -> f (Cofree f a) #
Comonad w => ComonadCofree Identity (CoiterT w) # |
Methods unwrap :: CoiterT w a -> Identity (CoiterT w a) #
(ComonadCofree f w, Monoid m) => ComonadCofree f (TracedT m w) # |
Methods unwrap :: TracedT m w a -> f (TracedT m w a) #
ComonadCofree f w => ComonadCofree f (StoreT s w) # |
Methods unwrap :: StoreT s w a -> f (StoreT s w a) #
ComonadCofree f w => ComonadCofree f (EnvT e w) # |
Methods unwrap :: EnvT e w a -> f (EnvT e w a) #
ComonadCofree f w => ComonadCofree f (IdentityT * w) # |
Methods unwrap :: IdentityT * w a -> f (IdentityT * w a) #
(Functor f, Comonad w) => ComonadCofree f (CofreeT f w) # |
Methods unwrap :: CofreeT f w a -> f (CofreeT f w a) #
ComonadCofree (Const * b) ((,) b) # |
Methods unwrap :: (b, a) -> Const * b (b, a) #

headF :: CofreeF f a b -> a #

Extract the head of the base functor

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

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 #

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 #

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