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

Control.Comonad

Description

(C) 2004 Dave Menendez License : BSD-style (see the file LICENSE)

Maintainer : Edward Kmett ekmett@gmail.com Stability : experimental Portability : portable

This module declares the Comonad class

Synopsis

Documentation

class Copointed w => Comonad w whereSource

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

duplicate :: w a -> w (w a)Source

extend :: (w a -> b) -> w a -> w bSource

liftW :: Comonad w => (a -> b) -> w a -> w bSource

(=>>) :: Comonad w => w a -> (w a -> b) -> w bSource

extend with the arguments swapped. Dual to >>= for monads.

(.>>) :: Comonad w => w a -> b -> w bSource

Injects a value into the comonad.

liftCtx :: Comonad w => (a -> b) -> w a -> bSource

Transform a function into a comonadic action

mapW :: Comonad w => (w a -> b) -> w [a] -> [b]Source

parallelW :: Comonad w => w [a] -> [w a]Source

unfoldW :: Comonad w => (w b -> (a, b)) -> w b -> [a]Source

sequenceW :: Comonad w => [w a -> b] -> w a -> [b]Source

Converts a list of comonadic functions into a single function returning a list of values