Category extrasSource codeContentsIndex
Control.Comonad
Portability portable
Stability experimental
Maintainer zednenem@psualum.com
Contents
The Comonad class
The coKleisli arrow
The product comonad
Additional functions
Description
This module declares the Comonad class, with instances for Id and ((,) a), and defines the CoKleisli arrow.
Synopsis
class Functor w => Comonad w where
extract :: w a -> a
duplicate :: w a -> w (w a)
extend :: (w a -> b) -> w a -> w b
(=>>) :: Comonad w => w a -> (w a -> b) -> w b
(.>>) :: Comonad w => w a -> b -> w b
liftW :: Comonad w => (a -> b) -> w a -> w b
newtype CoKleisli w a b = CoKleisli {
unCoKleisli :: (w a -> b)
}
local :: (c -> c') -> ((c', a) -> a) -> (c, a) -> a
sequenceW :: Comonad w => [w a -> b] -> w a -> [b]
The Comonad class
class Functor w => Comonad w where

There are two ways to define a comonad:

I. Provide definitions for fmap, extract, and duplicate satisfying these laws:

 extract . duplicate      == id
 fmap extract . duplicate == id
 duplicate . duplicate    == fmap duplicate . duplicate

II. Provide definitions for extract and extend satisfying these laws:

 extend extract      == id
 extract . extend f  == f
 extend f . extend g == extend (f . extend g)

(fmap cannot be defaulted, but a comonad which defines extend may simply set fmap equal to liftW.)

A comonad providing definitions for extend and duplicate, must also satisfy these laws:

 extend f  == fmap f . duplicate
 duplicate == extend id
 fmap f    == extend (f . duplicate)

(The first two are the defaults for extend and duplicate, and the third is the definition of liftW.)

Methods
extract :: w a -> a
duplicate :: w a -> w (w a)
extend :: (w a -> b) -> w a -> w b
Instances
Comonad Id
Comonad ((,) a)
Comonad (Context c)
Adjunction f g => Comonad (O f g)
Functor h => Comonad (Strf h)
Comonad ((->) Nat)
Comonad Tree
Comonad Stream
(=>>) :: Comonad w => w a -> (w a -> b) -> w b
extend with the arguments swapped. Dual to >>= for monads.
(.>>) :: Comonad w => w a -> b -> w b
Injects a value into the comonad.
liftW :: Comonad w => (a -> b) -> w a -> w b
fmap defined in terms of extend
The coKleisli arrow
newtype CoKleisli w a b
Constructors
CoKleisli
unCoKleisli :: (w a -> b)
Instances
Functor (CoKleisli w a)
Comonad w => Arrow (CoKleisli w)
The product comonad
local :: (c -> c') -> ((c', a) -> a) -> (c, a) -> a
Calls a comonadic function in a modified context
Additional functions
sequenceW :: Comonad w => [w a -> b] -> w a -> [b]
Converts a list of comonadic functions into a single function returning a list of values
Produced by Haddock version 0.6