Safe Haskell | Safe-Inferred |
---|---|

Language | Haskell2010 |

Utilities for functors.

## Synopsis

- (<.>) :: Functor m => (b -> c) -> (a -> m b) -> a -> m c
- for :: Functor m => m a -> (a -> b) -> m b
- class Functor t => Decoration t where
- traverseF :: Functor m => (a -> m b) -> t a -> m (t b)
- distributeF :: Functor m => t (m a) -> m (t a)

- dmap :: Decoration t => (a -> b) -> t a -> t b
- dget :: Decoration t => t a -> a
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- ($>) :: Functor f => f a -> b -> f b
- (<&>) :: Functor f => f a -> (a -> b) -> f b

# Documentation

(<.>) :: 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`

.

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`

.

Nothing

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

Decoration Ranged Source # | |

Decoration WithHiding Source # | |

Defined in Agda.Syntax.Common traverseF :: Functor m => (a -> m b) -> WithHiding a -> m (WithHiding b) Source # distributeF :: Functor m => WithHiding (m a) -> m (WithHiding a) Source # | |

Decoration WithOrigin Source # | |

Defined in Agda.Syntax.Common traverseF :: Functor m => (a -> m b) -> WithOrigin a -> m (WithOrigin b) Source # distributeF :: Functor m => WithOrigin (m a) -> m (WithOrigin a) Source # | |

Decoration Abs Source # | |

Decoration Masked Source # | |

Decoration Open Source # | |

Decoration Identity Source # | The identity functor is a decoration. |

Decoration (Named name) Source # | |

Decoration (Dom' t) Source # | |

Decoration (Type'' t) Source # | |

Decoration (Blocked' t) Source # | |

Decoration ((,) a) Source # | A typical decoration is pairing with some stuff. |

Defined in Agda.Utils.Functor | |

(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`

.

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

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

Convert from a

to a `Maybe`

`Int`

using `Maybe`

`String`

`show`

:

`>>>`

Nothing`show <$> Nothing`

`>>>`

Just "3"`show <$> Just 3`

Convert from an

to an
`Either`

`Int`

`Int`

`Either`

`Int`

`String`

using `show`

:

`>>>`

Left 17`show <$> Left 17`

`>>>`

Right "17"`show <$> Right 17`

Double each element of a list:

`>>>`

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

Apply `even`

to the second element of a pair:

`>>>`

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

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

Flipped version of `<$`

.

#### Examples

Replace the contents of a

with a constant
`Maybe`

`Int`

`String`

:

`>>>`

Nothing`Nothing $> "foo"`

`>>>`

Just "foo"`Just 90210 $> "foo"`

Replace the contents of an

with a constant `Either`

`Int`

`Int`

`String`

, resulting in an

:`Either`

`Int`

`String`

`>>>`

Left 8675309`Left 8675309 $> "foo"`

`>>>`

Right "foo"`Right 8675309 $> "foo"`

Replace each element of a list with a constant `String`

:

`>>>`

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

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

:

`>>>`

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

*Since: base-4.7.0.0*