Agda-2.5.1: A dependently typed functional programming language and proof assistant

Safe HaskellSafe
LanguageHaskell98

Agda.Utils.Functor

Contents

Description

Utilities for functors.

Synopsis

Documentation

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

(<.>) :: Functor m => (b -> c) -> (a -> m b) -> a -> m c infixr 9 Source

Composition: pure function after functorial (monadic) function.

for :: Functor m => m a -> (a -> b) -> m b Source

The true pure for loop. for is a misnomer, it should be forA.

(<&>) :: Functor m => m a -> (a -> b) -> m b infix 4 Source

Infix version of for.

class Functor t => Decoration t where Source

A decoration is a functor that is traversable into any functor.

The Functor superclass is given because of the limitations of the Haskell class system. traverseF actually implies functoriality.

Minimal complete definition: traverseF or distributeF.

Minimal complete definition

Nothing

Methods

traverseF :: Functor m => (a -> m b) -> t a -> m (t b) Source

traverseF is the defining property.

distributeF :: Functor m => t (m a) -> m (t a) Source

Decorations commute into any functor.

Instances

Decoration Identity Source

The identity functor is a decoration.

Decoration Ranged Source 
Decoration Dom Source 
Decoration Arg Source 
Decoration WithHiding Source 
Decoration Type' Source 
Decoration Abs Source 
Decoration Masked Source 
Decoration ((,) a) Source

A typical decoration is pairing with some stuff.

Decoration (Named name) Source 
(Decoration d, Decoration t) => Decoration (Compose d t) Source

Decorations compose. (Thus, they form a category.)

dmap :: Decoration t => (a -> b) -> t a -> t b Source

Any decoration is traversable with traverse = traverseF. Just like any Traversable is a functor, so is any decoration, given by just traverseF, a functor.

dget :: Decoration t => t a -> a Source

Any decoration is a lens. set is a special case of dmap.

The constant functor.

Maybe. Can only be traversed into pointed functors.

Other disjoint sum types, like lists etc.

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

An infix synonym for fmap.

Examples

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)