comonad-5.0.8: Comonads
Copyright(C) 2008-2015 Edward Kmett
(C) 2004 Dave Menendez
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Control.Comonad

Description

 
Synopsis

Comonads

class Functor w => Comonad w where Source #

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 Source #

extract . fmap f = f . extract

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

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

Instances

Instances details
Comonad Identity Source # 
Instance details

Defined in Control.Comonad

Comonad NonEmpty Source # 
Instance details

Defined in Control.Comonad

Comonad Tree Source # 
Instance details

Defined in Control.Comonad

Methods

extract :: Tree a -> a Source #

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

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

Comonad ((,) e) Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

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

Comonad (Arg e) Source # 
Instance details

Defined in Control.Comonad

Methods

extract :: Arg e a -> a Source #

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

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

Comonad (Tagged s) Source # 
Instance details

Defined in Control.Comonad

Methods

extract :: Tagged s a -> a Source #

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

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

Comonad w => Comonad (IdentityT w) Source # 
Instance details

Defined in Control.Comonad

Methods

extract :: IdentityT w a -> a Source #

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

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

Comonad w => Comonad (EnvT e w) Source # 
Instance details

Defined in Control.Comonad.Trans.Env

Methods

extract :: EnvT e w a -> a Source #

duplicate :: EnvT e w a -> EnvT e w (EnvT e w a) Source #

extend :: (EnvT e w a -> b) -> EnvT e w a -> EnvT e w b Source #

Comonad w => Comonad (StoreT s w) Source # 
Instance details

Defined in Control.Comonad.Trans.Store

Methods

extract :: StoreT s w a -> a Source #

duplicate :: StoreT s w a -> StoreT s w (StoreT s w a) Source #

extend :: (StoreT s w a -> b) -> StoreT s w a -> StoreT s w b Source #

(Comonad w, Monoid m) => Comonad (TracedT m w) Source # 
Instance details

Defined in Control.Comonad.Trans.Traced

Methods

extract :: TracedT m w a -> a Source #

duplicate :: TracedT m w a -> TracedT m w (TracedT m w a) Source #

extend :: (TracedT m w a -> b) -> TracedT m w a -> TracedT m w b Source #

Monoid m => Comonad ((->) m :: Type -> Type) Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

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

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

Defined in Control.Comonad

Methods

extract :: Sum f g a -> a Source #

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

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

liftW :: Comonad w => (a -> b) -> w a -> w b Source #

A suitable default definition for fmap for a Comonad. Promotes a function to a comonad.

You can only safely use liftW to define fmap if your Comonad defines extend, not just duplicate, since defining extend in terms of duplicate uses fmap!

fmap f = liftW f = extend (f . extract)

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

Comonadic fixed point à la David Menendez

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

Comonadic fixed point à la Dominic Orchard

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

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 Source #

Left-to-right Cokleisli composition

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

Right-to-left Cokleisli composition

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

extend in operator form

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

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

Combining Comonads

class Comonad w => ComonadApply w where Source #

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

Minimal complete definition

Nothing

Methods

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

default (<@>) :: Applicative w => w (a -> b) -> w a -> w b Source #

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

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

Instances

Instances details
ComonadApply Identity Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

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

ComonadApply NonEmpty Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

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

ComonadApply Tree Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

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

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

Defined in Control.Comonad

Methods

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

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

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

ComonadApply w => ComonadApply (IdentityT w) Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

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

(Semigroup e, ComonadApply w) => ComonadApply (EnvT e w) Source # 
Instance details

Defined in Control.Comonad.Trans.Env

Methods

(<@>) :: EnvT e w (a -> b) -> EnvT e w a -> EnvT e w b Source #

(@>) :: EnvT e w a -> EnvT e w b -> EnvT e w b Source #

(<@) :: EnvT e w a -> EnvT e w b -> EnvT e w a Source #

(ComonadApply w, Semigroup s) => ComonadApply (StoreT s w) Source # 
Instance details

Defined in Control.Comonad.Trans.Store

Methods

(<@>) :: StoreT s w (a -> b) -> StoreT s w a -> StoreT s w b Source #

(@>) :: StoreT s w a -> StoreT s w b -> StoreT s w b Source #

(<@) :: StoreT s w a -> StoreT s w b -> StoreT s w a Source #

(ComonadApply w, Monoid m) => ComonadApply (TracedT m w) Source # 
Instance details

Defined in Control.Comonad.Trans.Traced

Methods

(<@>) :: TracedT m w (a -> b) -> TracedT m w a -> TracedT m w b Source #

(@>) :: TracedT m w a -> TracedT m w b -> TracedT m w b Source #

(<@) :: TracedT m w a -> TracedT m w b -> TracedT m w a Source #

Monoid m => ComonadApply ((->) m :: Type -> Type) Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

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

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

A variant of <@> with the arguments reversed.

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

Lift a binary function into a Comonad with zipping

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

Lift a ternary function into a Comonad with zipping

Cokleisli Arrows

newtype Cokleisli w a b Source #

The Cokleisli Arrows of a given Comonad

Constructors

Cokleisli 

Fields

Instances

Instances details
Comonad w => Category (Cokleisli w :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Comonad

Methods

id :: forall (a :: k). Cokleisli w a a Source #

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

Comonad w => Arrow (Cokleisli w) Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

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

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

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

Comonad w => ArrowChoice (Cokleisli w) Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

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

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

Comonad w => ArrowApply (Cokleisli w) Source # 
Instance details

Defined in Control.Comonad

Methods

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

ComonadApply w => ArrowLoop (Cokleisli w) Source # 
Instance details

Defined in Control.Comonad

Methods

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

Monad (Cokleisli w a) Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

return :: a0 -> Cokleisli w a a0 Source #

Functor (Cokleisli w a) Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

Applicative (Cokleisli w a) Source # 
Instance details

Defined in Control.Comonad

Methods

pure :: a0 -> Cokleisli w a a0 Source #

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

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

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

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

Functors

class Functor (f :: Type -> Type) where Source #

A type f is a Functor if it provides a function fmap which, given any types a and b lets you apply any function from (a -> b) to turn an f a into an f b, preserving the structure of f. Furthermore f needs to adhere to the following:

Identity
fmap id == id
Composition
fmap (f . g) == fmap f . fmap g

Note, that the second law follows from the free theorem of the type fmap and the first law, so you need only check that the former condition holds.

Minimal complete definition

fmap

Methods

fmap :: (a -> b) -> f a -> f b Source #

Using ApplicativeDo: 'fmap f as' can be understood as the do expression

do a <- as
   pure (f a)

with an inferred Functor constraint.

(<$) :: a -> f b -> f a infixl 4 Source #

Replace all locations in the input with the same value. The default definition is fmap . const, but this may be overridden with a more efficient version.

Using ApplicativeDo: 'a <$ bs' can be understood as the do expression

do bs
   pure a

with an inferred Functor constraint.

Instances

Instances details
Functor []

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

fmap :: (a -> b) -> [a] -> [b] Source #

(<$) :: a -> [b] -> [a] Source #

Functor Maybe

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

fmap :: (a -> b) -> Maybe a -> Maybe b Source #

(<$) :: a -> Maybe b -> Maybe a Source #

Functor IO

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

fmap :: (a -> b) -> IO a -> IO b Source #

(<$) :: a -> IO b -> IO a Source #

Functor Par1

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> Par1 a -> Par1 b Source #

(<$) :: a -> Par1 b -> Par1 a Source #

Functor Complex

Since: base-4.9.0.0

Instance details

Defined in Data.Complex

Methods

fmap :: (a -> b) -> Complex a -> Complex b Source #

(<$) :: a -> Complex b -> Complex a Source #

Functor Min

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

fmap :: (a -> b) -> Min a -> Min b Source #

(<$) :: a -> Min b -> Min a Source #

Functor Max

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

fmap :: (a -> b) -> Max a -> Max b Source #

(<$) :: a -> Max b -> Max a Source #

Functor First

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

fmap :: (a -> b) -> First a -> First b Source #

(<$) :: a -> First b -> First a Source #

Functor Last

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

fmap :: (a -> b) -> Last a -> Last b Source #

(<$) :: a -> Last b -> Last a Source #

Functor Option

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

fmap :: (a -> b) -> Option a -> Option b Source #

(<$) :: a -> Option b -> Option a Source #

Functor ZipList

Since: base-2.1

Instance details

Defined in Control.Applicative

Methods

fmap :: (a -> b) -> ZipList a -> ZipList b Source #

(<$) :: a -> ZipList b -> ZipList a Source #

Functor Identity

Since: base-4.8.0.0

Instance details

Defined in Data.Functor.Identity

Methods

fmap :: (a -> b) -> Identity a -> Identity b Source #

(<$) :: a -> Identity b -> Identity a Source #

Functor First

Since: base-4.8.0.0

Instance details

Defined in Data.Monoid

Methods

fmap :: (a -> b) -> First a -> First b Source #

(<$) :: a -> First b -> First a Source #

Functor Last

Since: base-4.8.0.0

Instance details

Defined in Data.Monoid

Methods

fmap :: (a -> b) -> Last a -> Last b Source #

(<$) :: a -> Last b -> Last a Source #

Functor Dual

Since: base-4.8.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

fmap :: (a -> b) -> Dual a -> Dual b Source #

(<$) :: a -> Dual b -> Dual a Source #

Functor Sum

Since: base-4.8.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

fmap :: (a -> b) -> Sum a -> Sum b Source #

(<$) :: a -> Sum b -> Sum a Source #

Functor Product

Since: base-4.8.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

fmap :: (a -> b) -> Product a -> Product b Source #

(<$) :: a -> Product b -> Product a Source #

Functor Down

Since: base-4.11.0.0

Instance details

Defined in Data.Ord

Methods

fmap :: (a -> b) -> Down a -> Down b Source #

(<$) :: a -> Down b -> Down a Source #

Functor ReadP

Since: base-2.1

Instance details

Defined in Text.ParserCombinators.ReadP

Methods

fmap :: (a -> b) -> ReadP a -> ReadP b Source #

(<$) :: a -> ReadP b -> ReadP a Source #

Functor NonEmpty

Since: base-4.9.0.0

Instance details

Defined in GHC.Base

Methods

fmap :: (a -> b) -> NonEmpty a -> NonEmpty b Source #

(<$) :: a -> NonEmpty b -> NonEmpty a Source #

Functor IntMap 
Instance details

Defined in Data.IntMap.Internal

Methods

fmap :: (a -> b) -> IntMap a -> IntMap b Source #

(<$) :: a -> IntMap b -> IntMap a Source #

Functor Tree 
Instance details

Defined in Data.Tree

Methods

fmap :: (a -> b) -> Tree a -> Tree b Source #

(<$) :: a -> Tree b -> Tree a Source #

Functor Seq 
Instance details

Defined in Data.Sequence.Internal

Methods

fmap :: (a -> b) -> Seq a -> Seq b Source #

(<$) :: a -> Seq b -> Seq a Source #

Functor FingerTree 
Instance details

Defined in Data.Sequence.Internal

Methods

fmap :: (a -> b) -> FingerTree a -> FingerTree b Source #

(<$) :: a -> FingerTree b -> FingerTree a Source #

Functor Digit 
Instance details

Defined in Data.Sequence.Internal

Methods

fmap :: (a -> b) -> Digit a -> Digit b Source #

(<$) :: a -> Digit b -> Digit a Source #

Functor Node 
Instance details

Defined in Data.Sequence.Internal

Methods

fmap :: (a -> b) -> Node a -> Node b Source #

(<$) :: a -> Node b -> Node a Source #

Functor Elem 
Instance details

Defined in Data.Sequence.Internal

Methods

fmap :: (a -> b) -> Elem a -> Elem b Source #

(<$) :: a -> Elem b -> Elem a Source #

Functor ViewL 
Instance details

Defined in Data.Sequence.Internal

Methods

fmap :: (a -> b) -> ViewL a -> ViewL b Source #

(<$) :: a -> ViewL b -> ViewL a Source #

Functor ViewR 
Instance details

Defined in Data.Sequence.Internal

Methods

fmap :: (a -> b) -> ViewR a -> ViewR b Source #

(<$) :: a -> ViewR b -> ViewR a Source #

Functor P

Since: base-4.8.0.0

Instance details

Defined in Text.ParserCombinators.ReadP

Methods

fmap :: (a -> b) -> P a -> P b Source #

(<$) :: a -> P b -> P a Source #

Functor (Either a)

Since: base-3.0

Instance details

Defined in Data.Either

Methods

fmap :: (a0 -> b) -> Either a a0 -> Either a b Source #

(<$) :: a0 -> Either a b -> Either a a0 Source #

Functor (V1 :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> V1 a -> V1 b Source #

(<$) :: a -> V1 b -> V1 a Source #

Functor (U1 :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> U1 a -> U1 b Source #

(<$) :: a -> U1 b -> U1 a Source #

Functor ((,) a)

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

fmap :: (a0 -> b) -> (a, a0) -> (a, b) Source #

(<$) :: a0 -> (a, b) -> (a, a0) Source #

Functor (Array i)

Since: base-2.1

Instance details

Defined in GHC.Arr

Methods

fmap :: (a -> b) -> Array i a -> Array i b Source #

(<$) :: a -> Array i b -> Array i a Source #

Functor (Arg a)

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

fmap :: (a0 -> b) -> Arg a a0 -> Arg a b Source #

(<$) :: a0 -> Arg a b -> Arg a a0 Source #

Monad m => Functor (WrappedMonad m)

Since: base-2.1

Instance details

Defined in Control.Applicative

Methods

fmap :: (a -> b) -> WrappedMonad m a -> WrappedMonad m b Source #

(<$) :: a -> WrappedMonad m b -> WrappedMonad m a Source #

Arrow a => Functor (ArrowMonad a)

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

fmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b Source #

(<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 Source #

Functor (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

fmap :: (a -> b) -> Proxy a -> Proxy b Source #

(<$) :: a -> Proxy b -> Proxy a Source #

Functor (Map k) 
Instance details

Defined in Data.Map.Internal

Methods

fmap :: (a -> b) -> Map k a -> Map k b Source #

(<$) :: a -> Map k b -> Map k a Source #

Functor f => Functor (Rec1 f)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> Rec1 f a -> Rec1 f b Source #

(<$) :: a -> Rec1 f b -> Rec1 f a Source #

Functor (URec Char :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> URec Char a -> URec Char b Source #

(<$) :: a -> URec Char b -> URec Char a Source #

Functor (URec Double :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> URec Double a -> URec Double b Source #

(<$) :: a -> URec Double b -> URec Double a Source #

Functor (URec Float :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> URec Float a -> URec Float b Source #

(<$) :: a -> URec Float b -> URec Float a Source #

Functor (URec Int :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> URec Int a -> URec Int b Source #

(<$) :: a -> URec Int b -> URec Int a Source #

Functor (URec Word :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> URec Word a -> URec Word b Source #

(<$) :: a -> URec Word b -> URec Word a Source #

Functor (URec (Ptr ()) :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> URec (Ptr ()) a -> URec (Ptr ()) b Source #

(<$) :: a -> URec (Ptr ()) b -> URec (Ptr ()) a Source #

Functor ((,,) a b)

Since: base-4.14.0.0

Instance details

Defined in GHC.Base

Methods

fmap :: (a0 -> b0) -> (a, b, a0) -> (a, b, b0) Source #

(<$) :: a0 -> (a, b, b0) -> (a, b, a0) Source #

Arrow a => Functor (WrappedArrow a b)

Since: base-2.1

Instance details

Defined in Control.Applicative

Methods

fmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 Source #

(<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 Source #

Functor m => Functor (Kleisli m a)

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Methods

fmap :: (a0 -> b) -> Kleisli m a a0 -> Kleisli m a b Source #

(<$) :: a0 -> Kleisli m a b -> Kleisli m a a0 Source #

Functor (Const m :: Type -> Type)

Since: base-2.1

Instance details

Defined in Data.Functor.Const

Methods

fmap :: (a -> b) -> Const m a -> Const m b Source #

(<$) :: a -> Const m b -> Const m a Source #

Functor f => Functor (Ap f)

Since: base-4.12.0.0

Instance details

Defined in Data.Monoid

Methods

fmap :: (a -> b) -> Ap f a -> Ap f b Source #

(<$) :: a -> Ap f b -> Ap f a Source #

Functor f => Functor (Alt f)

Since: base-4.8.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

fmap :: (a -> b) -> Alt f a -> Alt f b Source #

(<$) :: a -> Alt f b -> Alt f a Source #

(Applicative f, Monad f) => Functor (WhenMissing f x)

Since: containers-0.5.9

Instance details

Defined in Data.IntMap.Internal

Methods

fmap :: (a -> b) -> WhenMissing f x a -> WhenMissing f x b Source #

(<$) :: a -> WhenMissing f x b -> WhenMissing f x a Source #

Functor f => Functor (Indexing f) 
Instance details

Defined in WithIndex

Methods

fmap :: (a -> b) -> Indexing f a -> Indexing f b Source #

(<$) :: a -> Indexing f b -> Indexing f a Source #

Functor (Tagged s) 
Instance details

Defined in Data.Tagged

Methods

fmap :: (a -> b) -> Tagged s a -> Tagged s b Source #

(<$) :: a -> Tagged s b -> Tagged s a Source #

Functor f => Functor (Reverse f)

Derived instance.

Instance details

Defined in Data.Functor.Reverse

Methods

fmap :: (a -> b) -> Reverse f a -> Reverse f b Source #

(<$) :: a -> Reverse f b -> Reverse f a Source #

Functor (Constant a :: Type -> Type) 
Instance details

Defined in Data.Functor.Constant

Methods

fmap :: (a0 -> b) -> Constant a a0 -> Constant a b Source #

(<$) :: a0 -> Constant a b -> Constant a a0 Source #

Functor m => Functor (ReaderT r m) 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

fmap :: (a -> b) -> ReaderT r m a -> ReaderT r m b Source #

(<$) :: a -> ReaderT r m b -> ReaderT r m a Source #

Functor m => Functor (IdentityT m) 
Instance details

Defined in Control.Monad.Trans.Identity

Methods

fmap :: (a -> b) -> IdentityT m a -> IdentityT m b Source #

(<$) :: a -> IdentityT m b -> IdentityT m a Source #

Functor f => Functor (Backwards f)

Derived instance.

Instance details

Defined in Control.Applicative.Backwards

Methods

fmap :: (a -> b) -> Backwards f a -> Backwards f b Source #

(<$) :: a -> Backwards f b -> Backwards f a Source #

Functor w => Functor (EnvT e w) Source # 
Instance details

Defined in Control.Comonad.Trans.Env

Methods

fmap :: (a -> b) -> EnvT e w a -> EnvT e w b Source #

(<$) :: a -> EnvT e w b -> EnvT e w a Source #

Functor w => Functor (StoreT s w) Source # 
Instance details

Defined in Control.Comonad.Trans.Store

Methods

fmap :: (a -> b) -> StoreT s w a -> StoreT s w b Source #

(<$) :: a -> StoreT s w b -> StoreT s w a Source #

Functor w => Functor (TracedT m w) Source # 
Instance details

Defined in Control.Comonad.Trans.Traced

Methods

fmap :: (a -> b) -> TracedT m w a -> TracedT m w b Source #

(<$) :: a -> TracedT m w b -> TracedT m w a Source #

Functor ((->) r :: Type -> Type)

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

fmap :: (a -> b) -> (r -> a) -> r -> b Source #

(<$) :: a -> (r -> b) -> r -> a Source #

Functor (K1 i c :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> K1 i c a -> K1 i c b Source #

(<$) :: a -> K1 i c b -> K1 i c a Source #

(Functor f, Functor g) => Functor (f :+: g)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> (f :+: g) a -> (f :+: g) b Source #

(<$) :: a -> (f :+: g) b -> (f :+: g) a Source #

(Functor f, Functor g) => Functor (f :*: g)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> (f :*: g) a -> (f :*: g) b Source #

(<$) :: a -> (f :*: g) b -> (f :*: g) a Source #

Functor ((,,,) a b c)

Since: base-4.14.0.0

Instance details

Defined in GHC.Base

Methods

fmap :: (a0 -> b0) -> (a, b, c, a0) -> (a, b, c, b0) Source #

(<$) :: a0 -> (a, b, c, b0) -> (a, b, c, a0) Source #

(Functor f, Functor g) => Functor (Product f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Product

Methods

fmap :: (a -> b) -> Product f g a -> Product f g b Source #

(<$) :: a -> Product f g b -> Product f g a Source #

(Functor f, Functor g) => Functor (Sum f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Sum

Methods

fmap :: (a -> b) -> Sum f g a -> Sum f g b Source #

(<$) :: a -> Sum f g b -> Sum f g a Source #

Functor f => Functor (WhenMatched f x y)

Since: containers-0.5.9

Instance details

Defined in Data.IntMap.Internal

Methods

fmap :: (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b Source #

(<$) :: a -> WhenMatched f x y b -> WhenMatched f x y a Source #

(Applicative f, Monad f) => Functor (WhenMissing f k x)

Since: containers-0.5.9

Instance details

Defined in Data.Map.Internal

Methods

fmap :: (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b Source #

(<$) :: a -> WhenMissing f k x b -> WhenMissing f k x a Source #

Functor (Cokleisli w a) Source # 
Instance details

Defined in Control.Comonad

Methods

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

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

Functor f => Functor (M1 i c f)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> M1 i c f a -> M1 i c f b Source #

(<$) :: a -> M1 i c f b -> M1 i c f a Source #

(Functor f, Functor g) => Functor (f :.: g)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

fmap :: (a -> b) -> (f :.: g) a -> (f :.: g) b Source #

(<$) :: a -> (f :.: g) b -> (f :.: g) a Source #

(Functor f, Functor g) => Functor (Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Methods

fmap :: (a -> b) -> Compose f g a -> Compose f g b Source #

(<$) :: a -> Compose f g b -> Compose f g a Source #

Functor f => Functor (WhenMatched f k x y)

Since: containers-0.5.9

Instance details

Defined in Data.Map.Internal

Methods

fmap :: (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b Source #

(<$) :: a -> WhenMatched f k x y b -> WhenMatched f k x y a Source #

(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 Source #

An infix synonym for fmap.

The name of this operator is an allusion to $. Note the similarities between their types:

 ($)  ::              (a -> b) ->   a ->   b
(<$>) :: Functor f => (a -> b) -> f a -> f b

Whereas $ is function application, <$> is function application lifted over a Functor.

Examples

Expand

Convert from a Maybe Int to a Maybe String using show:

>>> show <$> Nothing
Nothing
>>> show <$> Just 3
Just "3"

Convert from an Either Int Int to an Either Int String using show:

>>> show <$> Left 17
Left 17
>>> show <$> Right 17
Right "17"

Double each element of a list:

>>> (*2) <$> [1,2,3]
[2,4,6]

Apply even to the second element of a pair:

>>> even <$> (2,2)
(2,True)

($>) :: Functor f => f a -> b -> f b infixl 4 Source #

Flipped version of <$.

Using ApplicativeDo: 'as $> b' can be understood as the do expression

do as
   pure b

with an inferred Functor constraint.

Examples

Expand

Replace the contents of a Maybe Int with a constant String:

>>> Nothing $> "foo"
Nothing
>>> Just 90210 $> "foo"
Just "foo"

Replace the contents of an Either Int Int with a constant String, resulting in an Either Int String:

>>> Left 8675309 $> "foo"
Left 8675309
>>> Right 8675309 $> "foo"
Right "foo"

Replace each element of a list with a constant String:

>>> [1,2,3] $> "foo"
["foo","foo","foo"]

Replace the second element of a pair with a constant String:

>>> (1,2) $> "foo"
(1,"foo")

Since: base-4.7.0.0