Category extrasSource codeContentsIndex
Control.Functor
Portability portable
Stability experimental
Maintainer zednenem@psualum.com
Contents
Unary functors
Composition
Basic instances
Id
Unit
Const
Binary functors
Trinary functors
Description

Functor composition, standard functors, and more.

Note: declares functor instance for ((,) a)

Synopsis
newtype O f g a = Comp {
deComp :: (f (g a))
}
lComp :: Functor f => O f (O g h) a -> O (O f g) h a
rComp :: Functor f => O (O f g) h a -> O f (O g h) a
newtype Id a = Id {
unId :: a
}
data Unit a = Unit
data Const t a = Const {
unConst :: t
}
class Bifunctor f where
bimap :: (a -> c) -> (b -> d) -> f a b -> f c d
class Trifunctor f where
trimap :: (a -> a') -> (b -> b') -> (c -> c') -> f a b c -> f a' b' c'
Unary functors
Composition
newtype O f g a

Functor composition.

(Note: Some compilers will let you write f `O` g rather than O f g; we'll be doing so here for readability.)

Functor composition is associative, so f `O` (g `O` h) and (f `O` g) `O` h are equivalent. The functions lComp and rComp convert between the two. (Operationally, they are equivalent to id. Their only purpose is to affect the type system.)

Constructors
Comp
deComp :: (f (g a))
Instances
(Functor f, Functor g) => Functor (O f g)
Adjunction f g => Monad (O g f)
Adjunction f g => Comonad (O f g)
lComp :: Functor f => O f (O g h) a -> O (O f g) h a
rComp :: Functor f => O (O f g) h a -> O f (O g h) a
Basic instances
Id
newtype Id a
The identity functor (or a reasonable facsimile thereof).
Constructors
Id
unId :: a
Instances
Comonad Id
Functor Id
Monad Id
Show a => Show (Id a)
Unit
data Unit a

The unit functor.

(Note: this is not the same as (). In fact, Unit is the fixpoint of ().)

Constructors
Unit
Instances
Functor Unit
Monad Unit
Show (Unit a)
Fixpoint Unit ()
Const
data Const t a
Constant functors. Essentially the same as Unit, except that they also carry a value.
Constructors
Const
unConst :: t
Instances
Functor (Const t)
Show t => Show (Const t a)
Binary functors
class Bifunctor f where

A type constructor which takes two arguments and an associated map function.

Informally, Bifunctor f implies Functor (f a) with fmap = bimap id.

Methods
bimap :: (a -> c) -> (b -> d) -> f a b -> f c d
Instances
Bifunctor (,)
Bifunctor Either
Trinary functors
class Trifunctor f where

A type constructor which takes three arguments and an associated map function.

Informally, Trifunctor f implies Bifunctor (f a) with bimap = trimap id.

Methods
trimap :: (a -> a') -> (b -> b') -> (c -> c') -> f a b c -> f a' b' c'
Instances
Trifunctor (,,)
Produced by Haddock version 0.6