free-4.12.1: 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.Coiter

Contents

- The coiterative comonad transformer
- The coiterative comonad
- Generating coiterative comonads
- Cofree comonads
- Examples

Description

The coiterative comonad generated by a comonad

Synopsis

- newtype CoiterT w a = CoiterT {
  - runCoiterT :: w (a, CoiterT w a)
  }
- type Coiter = CoiterT Identity
- coiter :: a -> Coiter a -> Coiter a
- runCoiter :: Coiter a -> (a, Coiter a)
- unfold :: Comonad w => (w a -> a) -> w a -> CoiterT w a
- class (Functor f, Comonad w) => ComonadCofree f w | w -> f where
  - unwrap :: w a -> f (w a)

# Documentation

Coiterative comonads represent non-terminating, productive computations.

They are the dual notion of iterative monads. While iterative computations produce no values or eventually terminate with one, coiterative computations constantly produce values and they never terminate.

It's simpler form, `Coiter`, is an infinite stream of data. `CoiterT` extends this so that each step of the computation can be performed in a comonadic context.

# The coiterative comonad transformer

newtype CoiterT w a Source

This is the coiterative comonad generated by a comonad

Constructors

CoiterT |

Fields

runCoiterT :: w (a, CoiterT w a)

Instances

ComonadHoist CoiterT Source |
ComonadTrans CoiterT Source |
ComonadTraced m w => ComonadTraced m (CoiterT w) Source |
ComonadStore s w => ComonadStore s (CoiterT w) Source |
ComonadEnv e w => ComonadEnv e (CoiterT w) Source |
Comonad w => ComonadCofree Identity (CoiterT w) Source |
Functor w => Functor (CoiterT w) Source |
Foldable w => Foldable (CoiterT w) Source |
Traversable w => Traversable (CoiterT w) Source |
Comonad w => Comonad (CoiterT w) Source |
(Functor w, Eq1 w) => Eq1 (CoiterT w) Source |
(Functor w, Ord1 w) => Ord1 (CoiterT w) Source |
(Functor w, Show1 w) => Show1 (CoiterT w) Source |
(Functor w, Read1 w) => Read1 (CoiterT w) Source |
Eq (w (a, CoiterT w a)) => Eq (CoiterT w a) Source |
(Typeable (* -> *) w, Typeable * a, Data (w (a, CoiterT w a)), Data a) => Data (CoiterT w a) Source |
Ord (w (a, CoiterT w a)) => Ord (CoiterT w a) Source |
Read (w (a, CoiterT w a)) => Read (CoiterT w a) Source |
Show (w (a, CoiterT w a)) => Show (CoiterT w a) Source |

# The coiterative comonad

type Coiter = CoiterT Identity Source

The coiterative comonad

coiter :: a -> Coiter a -> Coiter a Source

Prepends a result to a coiterative computation.

    runCoiter . uncurry coiter == id

runCoiter :: Coiter a -> (a, Coiter a) Source

Extracts the first result from a coiterative computation.

    uncurry coiter . runCoiter == id

# Generating coiterative comonads

unfold :: Comonad w => (w a -> a) -> w a -> CoiterT w a Source

Unfold a `CoiterT` comonad transformer from a cokleisli arrow and an initial comonadic seed.

# Cofree comonads

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

Allows you to peel a layer off a cofree comonad.

Methods

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

Remove a layer.

Instances

ComonadCofree Maybe NonEmpty Source |
ComonadCofree f w => ComonadCofree f (IdentityT w) Source |
Functor f => ComonadCofree f (Cofree f) Source |
Comonad w => ComonadCofree Identity (CoiterT w) Source |
(ComonadCofree f w, Semigroup m, Monoid m) => ComonadCofree f (TracedT m w) Source |
ComonadCofree f w => ComonadCofree f (StoreT s w) Source |
ComonadCofree f w => ComonadCofree f (EnvT e w) Source |
(Functor f, Comonad w) => ComonadCofree f (CofreeT f w) Source |
ComonadCofree (Const b) ((,) b) Source |

# Examples

Newton's method