planet-mitchell-0.0.0: Planet Mitchell

Safe HaskellSafe
LanguageHaskell2010

Comonad

Contents

Synopsis

Comonad

class Functor w => Comonad (w :: * -> *) where #

There are two ways to define a comonad:

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

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

In this case, you may simply set fmap = liftW.

These laws are directly analogous to the laws for monads and perhaps can be made clearer by viewing them as laws stating that Cokleisli composition must be associative, and has extract for a unit:

f =>= extract   = f
extract =>= f   = f
(f =>= g) =>= h = f =>= (g =>= h)

II. Alternately, you may choose to provide definitions for fmap, extract, and duplicate satisfying these laws:

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

In this case you may not rely on the ability to define fmap in terms of liftW.

You may of course, choose to define both duplicate and extend. In that case you must also satisfy these laws:

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

These are the default definitions of extend and duplicate and the definition of liftW respectively.

Minimal complete definition

extract, (duplicate | extend)

Methods

extract :: w a -> a #

extract . fmap f = f . extract

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

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

Instances
Comonad Identity 
Instance details

Defined in Control.Comonad

Methods

extract :: Identity a -> a #

duplicate :: Identity a -> Identity (Identity a) #

extend :: (Identity a -> b) -> Identity a -> Identity b #

Comonad NonEmpty 
Instance details

Defined in Control.Comonad

Methods

extract :: NonEmpty a -> a #

duplicate :: NonEmpty a -> NonEmpty (NonEmpty a) #

extend :: (NonEmpty a -> b) -> NonEmpty a -> NonEmpty b #

Comonad Tree 
Instance details

Defined in Control.Comonad

Methods

extract :: Tree a -> a #

duplicate :: Tree a -> Tree (Tree a) #

extend :: (Tree a -> b) -> Tree a -> Tree b #

Comonad Log 
Instance details

Defined in Numeric.Log

Methods

extract :: Log a -> a #

duplicate :: Log a -> Log (Log a) #

extend :: (Log a -> b) -> Log a -> Log b #

Comonad ((,) e) 
Instance details

Defined in Control.Comonad

Methods

extract :: (e, a) -> a #

duplicate :: (e, a) -> (e, (e, a)) #

extend :: ((e, a) -> b) -> (e, a) -> (e, b) #

(Representable f, Monoid (Rep f)) => Comonad (Co f) 
Instance details

Defined in Data.Functor.Rep

Methods

extract :: Co f a -> a #

duplicate :: Co f a -> Co f (Co f a) #

extend :: (Co f a -> b) -> Co f a -> Co f b #

Comonad (Arg e) 
Instance details

Defined in Control.Comonad

Methods

extract :: Arg e a -> a #

duplicate :: Arg e a -> Arg e (Arg e a) #

extend :: (Arg e a -> b) -> Arg e a -> Arg e b #

Comonad (Fold a) 
Instance details

Defined in Control.Foldl

Methods

extract :: Fold a a0 -> a0 #

duplicate :: Fold a a0 -> Fold a (Fold a a0) #

extend :: (Fold a a0 -> b) -> Fold a a0 -> Fold a b #

Functor f => Comonad (Cofree f) 
Instance details

Defined in Control.Comonad.Cofree

Methods

extract :: Cofree f a -> a #

duplicate :: Cofree f a -> Cofree f (Cofree f a) #

extend :: (Cofree f a -> b) -> Cofree f a -> Cofree f b #

Comonad f => Comonad (Ap f) 
Instance details

Defined in Control.Applicative.Free

Methods

extract :: Ap f a -> a #

duplicate :: Ap f a -> Ap f (Ap f a) #

extend :: (Ap f a -> b) -> Ap f a -> Ap f b #

Comonad w => Comonad (Yoneda w) 
Instance details

Defined in Data.Functor.Yoneda

Methods

extract :: Yoneda w a -> a #

duplicate :: Yoneda w a -> Yoneda w (Yoneda w a) #

extend :: (Yoneda w a -> b) -> Yoneda w a -> Yoneda w b #

Monoid s => Comonad (ReifiedGetter s) 
Instance details

Defined in Control.Lens.Reified

Comonad f => Comonad (MaybeApply f) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

extract :: MaybeApply f a -> a #

duplicate :: MaybeApply f a -> MaybeApply f (MaybeApply f a) #

extend :: (MaybeApply f a -> b) -> MaybeApply f a -> MaybeApply f b #

Comonad w => Comonad (IdentityT w) 
Instance details

Defined in Control.Comonad

Methods

extract :: IdentityT w a -> a #

duplicate :: IdentityT w a -> IdentityT w (IdentityT w a) #

extend :: (IdentityT w a -> b) -> IdentityT w a -> IdentityT w b #

(Functor f, Comonad w) => Comonad (CofreeT f w) 
Instance details

Defined in Control.Comonad.Trans.Cofree

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 #

(Comonad f, Comonad g) => Comonad (Day f g) 
Instance details

Defined in Data.Functor.Day

Methods

extract :: Day f g a -> a #

duplicate :: Day f g a -> Day f g (Day f g a) #

extend :: (Day f g a -> b) -> Day f g a -> Day f g b #

a ~ b => Comonad (Context a b) 
Instance details

Defined in Control.Lens.Internal.Context

Methods

extract :: Context a b a0 -> a0 #

duplicate :: Context a b a0 -> Context a b (Context a b a0) #

extend :: (Context a b a0 -> b0) -> Context a b a0 -> Context a b b0 #

(Comonad f, Monoid a) => Comonad (Static f a) 
Instance details

Defined in Data.Semigroupoid.Static

Methods

extract :: Static f a a0 -> a0 #

duplicate :: Static f a a0 -> Static f a (Static f a a0) #

extend :: (Static f a a0 -> b) -> Static f a a0 -> Static f a b #

Comonad (Tagged s) 
Instance details

Defined in Control.Comonad

Methods

extract :: Tagged s a -> a #

duplicate :: Tagged s a -> Tagged s (Tagged s a) #

extend :: (Tagged s a -> b) -> Tagged s a -> Tagged s b #

Monoid m => Comonad ((->) m :: * -> *) 
Instance details

Defined in Control.Comonad

Methods

extract :: (m -> a) -> a #

duplicate :: (m -> a) -> m -> m -> a #

extend :: ((m -> a) -> b) -> (m -> a) -> m -> b #

(Comonad f, Comonad g) => Comonad (Sum f g) 
Instance details

Defined in Control.Comonad

Methods

extract :: Sum f g a -> a #

duplicate :: Sum f g a -> Sum f g (Sum f g a) #

extend :: (Sum f g a -> b) -> Sum f g a -> Sum f g b #

a ~ b => Comonad (Molten i a b) 
Instance details

Defined in Control.Lens.Internal.Magma

Methods

extract :: Molten i a b a0 -> a0 #

duplicate :: Molten i a b a0 -> Molten i a b (Molten i a b a0) #

extend :: (Molten i a b a0 -> b0) -> Molten i a b a0 -> Molten i a b b0 #

(a ~ b, Conjoined p) => Comonad (Bazaar p a b) 
Instance details

Defined in Control.Lens.Internal.Bazaar

Methods

extract :: Bazaar p a b a0 -> a0 #

duplicate :: Bazaar p a b a0 -> Bazaar p a b (Bazaar p a b a0) #

extend :: (Bazaar p a b a0 -> b0) -> Bazaar p a b a0 -> Bazaar p a b b0 #

(a ~ b, Conjoined p) => Comonad (Bazaar1 p a b) 
Instance details

Defined in Control.Lens.Internal.Bazaar

Methods

extract :: Bazaar1 p a b a0 -> a0 #

duplicate :: Bazaar1 p a b a0 -> Bazaar1 p a b (Bazaar1 p a b a0) #

extend :: (Bazaar1 p a b a0 -> b0) -> Bazaar1 p a b a0 -> Bazaar1 p a b b0 #

(a ~ b, Conjoined p) => Comonad (Pretext p a b) 
Instance details

Defined in Control.Lens.Internal.Context

Methods

extract :: Pretext p a b a0 -> a0 #

duplicate :: Pretext p a b a0 -> Pretext p a b (Pretext p a b a0) #

extend :: (Pretext p a b a0 -> b0) -> Pretext p a b a0 -> Pretext p a b b0 #

(a ~ b, Conjoined p) => Comonad (BazaarT p g a b) 
Instance details

Defined in Control.Lens.Internal.Bazaar

Methods

extract :: BazaarT p g a b a0 -> a0 #

duplicate :: BazaarT p g a b a0 -> BazaarT p g a b (BazaarT p g a b a0) #

extend :: (BazaarT p g a b a0 -> b0) -> BazaarT p g a b a0 -> BazaarT p g a b b0 #

(a ~ b, Conjoined p) => Comonad (BazaarT1 p g a b) 
Instance details

Defined in Control.Lens.Internal.Bazaar

Methods

extract :: BazaarT1 p g a b a0 -> a0 #

duplicate :: BazaarT1 p g a b a0 -> BazaarT1 p g a b (BazaarT1 p g a b a0) #

extend :: (BazaarT1 p g a b a0 -> b0) -> BazaarT1 p g a b a0 -> BazaarT1 p g a b b0 #

(a ~ b, Conjoined p) => Comonad (PretextT p g a b) 
Instance details

Defined in Control.Lens.Internal.Context

Methods

extract :: PretextT p g a b a0 -> a0 #

duplicate :: PretextT p g a b a0 -> PretextT p g a b (PretextT p g a b a0) #

extend :: (PretextT p g a b a0 -> b0) -> PretextT p g a b a0 -> PretextT p g a b b0 #

wfix :: Comonad w => w (w a -> a) -> a #

Comonadic fixed point à la David Menendez

cfix :: Comonad w => (w a -> a) -> w a #

Comonadic fixed point à la Dominic Orchard

kfix :: ComonadApply w => w (w a -> a) -> w a #

Comonadic fixed point à la Kenneth Foner:

This is the evaluate function from his "Getting a Quick Fix on Comonads" talk.

(=>=) :: Comonad w => (w a -> b) -> (w b -> c) -> w a -> c infixr 1 #

Left-to-right Cokleisli composition

(=<=) :: Comonad w => (w b -> c) -> (w a -> b) -> w a -> c infixr 1 #

Right-to-left Cokleisli composition

(<<=) :: Comonad w => (w a -> b) -> w a -> w b infixr 1 #

extend in operator form

(=>>) :: Comonad w => w a -> (w a -> b) -> w b infixl 1 #

extend with the arguments swapped. Dual to >>= for a Monad.

ComonadApply

class Comonad w => ComonadApply (w :: * -> *) where #

ComonadApply is to Comonad like Applicative is to Monad.

Mathematically, it is a strong lax symmetric semi-monoidal comonad on the category Hask of Haskell types. That it to say that w is a strong lax symmetric semi-monoidal functor on Hask, where both extract and duplicate are symmetric monoidal natural transformations.

Laws:

(.) <$> u <@> v <@> w = u <@> (v <@> w)
extract (p <@> q) = extract p (extract q)
duplicate (p <@> q) = (<@>) <$> duplicate p <@> duplicate q

If our type is both a ComonadApply and Applicative we further require

(<*>) = (<@>)

Finally, if you choose to define (<@) and (@>), the results of your definitions should match the following laws:

a @> b = const id <$> a <@> b
a <@ b = const <$> a <@> b

Methods

(<@>) :: w (a -> b) -> w a -> w b infixl 4 #

(@>) :: w a -> w b -> w b infixl 4 #

(<@) :: w a -> w b -> w a infixl 4 #

Instances
ComonadApply Identity 
Instance details

Defined in Control.Comonad

Methods

(<@>) :: Identity (a -> b) -> Identity a -> Identity b #

(@>) :: Identity a -> Identity b -> Identity b #

(<@) :: Identity a -> Identity b -> Identity a #

ComonadApply NonEmpty 
Instance details

Defined in Control.Comonad

Methods

(<@>) :: NonEmpty (a -> b) -> NonEmpty a -> NonEmpty b #

(@>) :: NonEmpty a -> NonEmpty b -> NonEmpty b #

(<@) :: NonEmpty a -> NonEmpty b -> NonEmpty a #

ComonadApply Tree 
Instance details

Defined in Control.Comonad

Methods

(<@>) :: Tree (a -> b) -> Tree a -> Tree b #

(@>) :: Tree a -> Tree b -> Tree b #

(<@) :: Tree a -> Tree b -> Tree a #

ComonadApply Log 
Instance details

Defined in Numeric.Log

Methods

(<@>) :: Log (a -> b) -> Log a -> Log b #

(@>) :: Log a -> Log b -> Log b #

(<@) :: Log a -> Log b -> Log a #

Semigroup m => ComonadApply ((,) m) 
Instance details

Defined in Control.Comonad

Methods

(<@>) :: (m, a -> b) -> (m, a) -> (m, b) #

(@>) :: (m, a) -> (m, b) -> (m, b) #

(<@) :: (m, a) -> (m, b) -> (m, a) #

ComonadApply f => ComonadApply (Cofree f) 
Instance details

Defined in Control.Comonad.Cofree

Methods

(<@>) :: Cofree f (a -> b) -> Cofree f a -> Cofree f b #

(@>) :: Cofree f a -> Cofree f b -> Cofree f b #

(<@) :: Cofree f a -> Cofree f b -> Cofree f a #

Monoid s => ComonadApply (ReifiedGetter s) 
Instance details

Defined in Control.Lens.Reified

Methods

(<@>) :: ReifiedGetter s (a -> b) -> ReifiedGetter s a -> ReifiedGetter s b #

(@>) :: ReifiedGetter s a -> ReifiedGetter s b -> ReifiedGetter s b #

(<@) :: ReifiedGetter s a -> ReifiedGetter s b -> ReifiedGetter s a #

ComonadApply w => ComonadApply (IdentityT w) 
Instance details

Defined in Control.Comonad

Methods

(<@>) :: IdentityT w (a -> b) -> IdentityT w a -> IdentityT w b #

(@>) :: IdentityT w a -> IdentityT w b -> IdentityT w b #

(<@) :: IdentityT w a -> IdentityT w b -> IdentityT w a #

(ComonadApply f, ComonadApply g) => ComonadApply (Day f g) 
Instance details

Defined in Data.Functor.Day

Methods

(<@>) :: Day f g (a -> b) -> Day f g a -> Day f g b #

(@>) :: Day f g a -> Day f g b -> Day f g b #

(<@) :: Day f g a -> Day f g b -> Day f g a #

Monoid m => ComonadApply ((->) m :: * -> *) 
Instance details

Defined in Control.Comonad

Methods

(<@>) :: (m -> a -> b) -> (m -> a) -> m -> b #

(@>) :: (m -> a) -> (m -> b) -> m -> b #

(<@) :: (m -> a) -> (m -> b) -> m -> a #

(a ~ b, Conjoined p) => ComonadApply (Bazaar p a b) 
Instance details

Defined in Control.Lens.Internal.Bazaar

Methods

(<@>) :: Bazaar p a b (a0 -> b0) -> Bazaar p a b a0 -> Bazaar p a b b0 #

(@>) :: Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b b0 #

(<@) :: Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b a0 #

(a ~ b, Conjoined p) => ComonadApply (Bazaar1 p a b) 
Instance details

Defined in Control.Lens.Internal.Bazaar

Methods

(<@>) :: Bazaar1 p a b (a0 -> b0) -> Bazaar1 p a b a0 -> Bazaar1 p a b b0 #

(@>) :: Bazaar1 p a b a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b b0 #

(<@) :: Bazaar1 p a b a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b a0 #

(a ~ b, Conjoined p) => ComonadApply (BazaarT p g a b) 
Instance details

Defined in Control.Lens.Internal.Bazaar

Methods

(<@>) :: BazaarT p g a b (a0 -> b0) -> BazaarT p g a b a0 -> BazaarT p g a b b0 #

(@>) :: BazaarT p g a b a0 -> BazaarT p g a b b0 -> BazaarT p g a b b0 #

(<@) :: BazaarT p g a b a0 -> BazaarT p g a b b0 -> BazaarT p g a b a0 #

(a ~ b, Conjoined p) => ComonadApply (BazaarT1 p g a b) 
Instance details

Defined in Control.Lens.Internal.Bazaar

Methods

(<@>) :: BazaarT1 p g a b (a0 -> b0) -> BazaarT1 p g a b a0 -> BazaarT1 p g a b b0 #

(@>) :: BazaarT1 p g a b a0 -> BazaarT1 p g a b b0 -> BazaarT1 p g a b b0 #

(<@) :: BazaarT1 p g a b a0 -> BazaarT1 p g a b b0 -> BazaarT1 p g a b a0 #

(<@@>) :: ComonadApply w => w a -> w (a -> b) -> w b infixl 4 #

A variant of <@> with the arguments reversed.

liftW2 :: ComonadApply w => (a -> b -> c) -> w a -> w b -> w c #

Lift a binary function into a Comonad with zipping

liftW3 :: ComonadApply w => (a -> b -> c -> d) -> w a -> w b -> w c -> w d #

Lift a ternary function into a Comonad with zipping

Newtypes

newtype Cokleisli (w :: k -> *) (a :: k) b :: forall k. (k -> *) -> k -> * -> * #

The Cokleisli Arrows of a given Comonad

Constructors

Cokleisli 

Fields

Instances
Comonad w => Category (Cokleisli w :: * -> * -> *) 
Instance details

Defined in Control.Comonad

Methods

id :: Cokleisli w a a #

(.) :: Cokleisli w b c -> Cokleisli w a b -> Cokleisli w a c #

Extend w => Semigroupoid (Cokleisli w :: * -> * -> *) 
Instance details

Defined in Data.Semigroupoid

Methods

o :: Cokleisli w j k1 -> Cokleisli w i j -> Cokleisli w i k1 #

Comonad w => Arrow (Cokleisli w) 
Instance details

Defined in Control.Comonad

Methods

arr :: (b -> c) -> Cokleisli w b c #

first :: Cokleisli w b c -> Cokleisli w (b, d) (c, d) #

second :: Cokleisli w b c -> Cokleisli w (d, b) (d, c) #

(***) :: Cokleisli w b c -> Cokleisli w b' c' -> Cokleisli w (b, b') (c, c') #

(&&&) :: Cokleisli w b c -> Cokleisli w b c' -> Cokleisli w b (c, c') #

Comonad w => ArrowChoice (Cokleisli w) 
Instance details

Defined in Control.Comonad

Methods

left :: Cokleisli w b c -> Cokleisli w (Either b d) (Either c d) #

right :: Cokleisli w b c -> Cokleisli w (Either d b) (Either d c) #

(+++) :: Cokleisli w b c -> Cokleisli w b' c' -> Cokleisli w (Either b b') (Either c c') #

(|||) :: Cokleisli w b d -> Cokleisli w c d -> Cokleisli w (Either b c) d #

Comonad w => ArrowApply (Cokleisli w) 
Instance details

Defined in Control.Comonad

Methods

app :: Cokleisli w (Cokleisli w b c, b) c #

ComonadApply w => ArrowLoop (Cokleisli w) 
Instance details

Defined in Control.Comonad

Methods

loop :: Cokleisli w (b, d) (c, d) -> Cokleisli w b c #

Functor w => Profunctor (Cokleisli w) 
Instance details

Defined in Data.Profunctor.Unsafe

Methods

dimap :: (a -> b) -> (c -> d) -> Cokleisli w b c -> Cokleisli w a d #

lmap :: (a -> b) -> Cokleisli w b c -> Cokleisli w a c #

rmap :: (b -> c) -> Cokleisli w a b -> Cokleisli w a c #

(#.) :: Coercible c b => (b -> c) -> Cokleisli w a b -> Cokleisli w a c #

(.#) :: Coercible b a => Cokleisli w b c -> (a -> b) -> Cokleisli w a c #

Functor w => Corepresentable (Cokleisli w) 
Instance details

Defined in Data.Profunctor.Rep

Associated Types

type Corep (Cokleisli w) :: * -> * #

Methods

cotabulate :: (Corep (Cokleisli w) d -> c) -> Cokleisli w d c #

Comonad w => Choice (Cokleisli w)

extract approximates costrength

Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Cokleisli w a b -> Cokleisli w (Either a c) (Either b c) #

right' :: Cokleisli w a b -> Cokleisli w (Either c a) (Either c b) #

Functor f => Closed (Cokleisli f) 
Instance details

Defined in Data.Profunctor.Closed

Methods

closed :: Cokleisli f a b -> Cokleisli f (x -> a) (x -> b) #

Functor f => Costrong (Cokleisli f) 
Instance details

Defined in Data.Profunctor.Strong

Methods

unfirst :: Cokleisli f (a, d) (b, d) -> Cokleisli f a b #

unsecond :: Cokleisli f (d, a) (d, b) -> Cokleisli f a b #

Monad (Cokleisli w a) 
Instance details

Defined in Control.Comonad

Methods

(>>=) :: Cokleisli w a a0 -> (a0 -> Cokleisli w a b) -> Cokleisli w a b #

(>>) :: Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a b #

return :: a0 -> Cokleisli w a a0 #

fail :: String -> Cokleisli w a a0 #

Functor (Cokleisli w a) 
Instance details

Defined in Control.Comonad

Methods

fmap :: (a0 -> b) -> Cokleisli w a a0 -> Cokleisli w a b #

(<$) :: a0 -> Cokleisli w a b -> Cokleisli w a a0 #

Applicative (Cokleisli w a) 
Instance details

Defined in Control.Comonad

Methods

pure :: a0 -> Cokleisli w a a0 #

(<*>) :: Cokleisli w a (a0 -> b) -> Cokleisli w a a0 -> Cokleisli w a b #

liftA2 :: (a0 -> b -> c) -> Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a c #

(*>) :: Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a b #

(<*) :: Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a a0 #

Apply (Cokleisli w a) 
Instance details

Defined in Data.Functor.Bind.Class

Methods

(<.>) :: Cokleisli w a (a0 -> b) -> Cokleisli w a a0 -> Cokleisli w a b #

(.>) :: Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a b #

(<.) :: Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a a0 #

liftF2 :: (a0 -> b -> c) -> Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a c #

Pointed (Cokleisli w a) 
Instance details

Defined in Data.Pointed

Methods

point :: a0 -> Cokleisli w a a0 #

type Corep (Cokleisli w) 
Instance details

Defined in Data.Profunctor.Rep

type Corep (Cokleisli w) = w