## Concept:

# Functor

## Headline

A functional programming idiom for mapping over containers

## Illustration

The term "functor" originates from category theory, but this will be of no further concern in this description. In functional programming, "functor" refers to a programming idiom for mapping over contains or compound data. Functors have been popularized by Language:Haskell.

In Haskell, functors are programmed and used with the help of the type class *Functor* which is parametrized by a type constructor for the actual container type:

```
class Functor f
where
fmap :: (a -> b) -> f a -> f b
```

The type constructor parameter *f* is the placeholder for the actual container type. The fmap function (for "functorial map") is the principle operation of a functor: parametrized by a function for mapping container elements of type *a* to elements of type *b*, it provides a mapping at the level of the container types, from *f a* to *f b*. Algebraically, the following properties are required for any functor (given in Haskell notation):

```
fmap id = id
fmap f . fmap g = fmap (f . g)
```

The following *Functor* instance turns lists into a functor:

```
instance Functor []
where
fmap = map
```

Thus, the folklore map function for list processing is a particular example of the notion of functorial map.

Here is another *Functor* instance turning the Maybe type constructor into a functor.

```
instance Functor Maybe
where
fmap _ Nothing = Nothing
fmap f (Just x) = Just (f x)
```

See also the concept of rose trees for more complicated examples of functors.

### There are no revisions for this page.

## User contributions

## User edits

## Syntax for editing wiki

For you are available next options:will make text bold.

will make text italic.

will make text underlined.

will make text striked.

will allow you to paste code headline into the page.

will allow you to link into the page.

will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

will allow you to paste image into the page.

is list with bullets.

is list with numbers.

will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

will allow your to insert code snippets from
**
@worker.
**

## Syntax for editing wiki

For you are available next options:will make text bold.

will make text italic.

will make text underlined.

will make text striked.

will allow you to paste code headline into the page.

will allow you to link into the page.

will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

will allow you to paste image into the page.

is list with bullets.

is list with numbers.

will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

will allow your to insert code snippets from
**
@worker.
**