category-extras-0.44.4: Various modules and constructs inspired by category theory

Portabilityrank-2 types
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>

Control.Comonad.Cofree

Description

 

Synopsis

Documentation

newtype BiffB p f g a b Source

Constructors

BiffB 

Fields

runBiffB :: p (f a) (g b)
 

Instances

newtype FixB s a Source

Constructors

InB 

Fields

outB :: s a (FixB s a)
 

Instances

PMonad f => Monad (FixB f) 
Bifunctor s => Functor (FixB s) 
PCopointed f => Copointed (FixB f) 
PPointed f => Pointed (FixB f) 
PComonad f => Comonad (FixB f) 
Bizip p => Zip (FixB p) 

class Bifunctor f => PCopointed f whereSource

Methods

pextract :: f a c -> aSource

Instances

class PCopointed f => PComonad f whereSource

Methods

pextend :: (f b c -> a) -> f b c -> f a cSource

Instances

newtype Identity a

Identity wrapper. Abstraction for wrapping up a object. If you have an monadic function, say:

   example :: Int -> Identity Int
   example x = return (x*x)

you can "run" it, using

 Main> runIdentity (example 42)
 1764 :: Int

A typical use of the Identity monad is to derive a monad from a monad transformer.

-- derive the Control.Monad.State.State monad using the Control.Monad.State.StateT monad transformer
type Control.Monad.State.State s a = Control.Monad.State.StateT s Identity a

The runIdentity label is used in the type definition because it follows a style of monad definition that explicitly represents monad values as computations. In this style, a monadic computation is built up using the monadic operators and then the value of the computation is extracted using the run****** function. Because the Identity monad does not do any computation, its definition is trivial. For a better example of this style of monad, see the Control.Monad.State.State monad.

Constructors

Identity 

Fields

runIdentity :: a
 

type CofreeB f a b = BiffB (,) Identity f a bSource

outCofree :: Cofree f a -> f (Cofree f a)Source

runCofree :: Cofree f a -> (a, f (Cofree f a))Source

anaCofree :: Functor f => (a -> c) -> (a -> f a) -> a -> Cofree f cSource

cofree :: a -> f (Cofree f a) -> Cofree f aSource