Lesson plan
Functor (functional programming)
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. In Haskell this idea can be captured in a type class: class Functor f where fmap :: (a -> b) -> f a -> f b This declaration says that any instance of Functor must support a method fmap , which maps a function over the elements of the instance. Functors in Haskell should also obey the so-called functor laws, which state that the mapping operation preserves the identity function and composition of functions: fmap id = id fmap (g . h) = (fmap g) . (fmap h) where . stands for function composition. In Scala a trait can instead be used: trait Functor[F[_ { def map[A,B](a: F[A])(f: A => B): F[B] } Functors form a base for more complex abstractions like applicative functors, monads, and comonads, all of which build atop a canonical functor structure. Functors are useful in modeling functional effects by values of parameterized data types. Modifiable computations are modeled by allowing a pure function to be applied to values of the "inner" type, thus creating the new overall value which represents the modified computation (which may have yet to run).
Article summary
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. In Haskell this idea can be captured in a type class: class Functor f where fmap :: (a -> b) -> f a -> f b This declaration says that any instance of Functor must support a method fmap , which maps a function over the elements of the instance. Functors in Haskell should also obey the so-called functor laws, which state that the mapping operation preserves the identity function and composition of functions: fmap id = id fmap (g . h) = (fmap g) . (fmap h) where . stands for function composition. In Scala a trait can instead be used: trait Functor[F[_ { def map[A,B](a: F[A])(f: A => B): F[B] } Functors form a base for more complex abstractions like applicative functors, monads, and comonads, all of which build atop a canonical functor structure. Functors are useful in modeling functional effects by values of parameterized data types. Modifiable computations are modeled by allowing a pure function to be applied to values of the "inner" type, thus creating the new overall value which represents the modified computation (which may have yet to run).
Key claims
No claims recorded.
Discussion questions
- Summarise the article in your own words. Which single claim would you verify first, and why?
- Which claim in this article is most likely to be revised as the sources update? How would you check its current status?
- If two sources disagreed about one of these facts, what would you need in order to trust one over the other?
Bibliography
No sources recorded.
Key claims and bibliography are generated from the same tracked claims and sources as the article page.