Functional Programming

2 thoughts
last posted April 21, 2015, 5:46 a.m.
0
get stream as: markdown or atom
0

Functor

A functor is a container-like data structure that allows one to apply a function to all its contents.

That is, for a list or an option type, the map operation returns a new list or option where the given function was applied to the contents of the object.

Or, looking at it another way, you can compose a "functor" with a function such that any value that "come out" of the data structure are passed through the function of your choice. From this perspective the data structure is used like a (partial) function composed with another function.

0

Applicative Functor

An Applicative Functor is a class which provides a pair of operations - one that lifts values into an instance of the functor, and one which lifts functions into mappings of the functor.

In a category theory sense the Applicative Functor is a functor from the language's objects and functions to the category of instances of the functor and mappings of that functor.

This is in addition to the interpretation of the Functor itself as a category theory style functor from classes (using the Functor's type constructor to translate the class) and functions (translating a function to a function that maps over instances of the functor).