Search results
Results from the WOW.Com Content Network
Applying fmap (+1) to a binary tree of integers increments each integer in the tree by one.. In functional programming, a functor is a design pattern inspired by the definition from category theory that allows one to apply a function to values inside a generic type without changing the structure of the generic type.
For example, the initial object in any concrete category with free objects will be the free object generated by the empty set (since the free functor, being left adjoint to the forgetful functor to Set, preserves colimits). Initial and terminal objects may also be characterized in terms of universal properties and adjoint functors.
The ML family of functional programming languages uses the term functor to represent a mapping from modules to modules, or from types to types and is a technique for reusing code. Functors used in this manner are analogous to the original mathematical meaning of functor in category theory , or to the use of generic programming in C++, Java or Ada .
A functor from G to Set is then nothing but a group action of G on a particular set, i.e. a G-set. Likewise, a functor from G to the category of vector spaces, Vect K, is a linear representation of G. In general, a functor G → C can be considered as an "action" of G on an object in the category C. If C is a group, then this action is a group ...
A faithful functor need not be injective on objects or morphisms. That is, two objects X and X′ may map to the same object in D (which is why the range of a full and faithful functor is not necessarily isomorphic to C), and two morphisms f : X → Y and f′ : X′ → Y′ (with different domains/codomains) may map to the same morphism in D.
This is where a free monad comes in; as a free object in the category of monads, it can represent monadic structure without any specific constraints beyond the monad laws themselves. Just as a free monoid concatenates elements without evaluation, a free monad allows chaining computations with markers to satisfy the type system, but otherwise ...
Suppose is a small category (i.e. the objects and morphisms form a set rather than a proper class) and is an arbitrary category. The category of functors from to , written as Fun(, ), Funct(,), [,], or , has as objects the covariant functors from to , and as morphisms the natural transformations between such functors.
In Haskell, the polymorphic function map :: (a -> b) -> [a] -> [b] is generalized to a polytypic function fmap :: Functor f => (a -> b) -> f a -> f b, which applies to any type belonging the Functor type class. The type constructor of lists [] can be defined as an instance of the Functor type class using the map function from the previous example: