September 2017
Beginner to intermediate
396 pages
9h 46m
English
The Data.Functor module defines the type class Functor. The Functor class is available from Prelude, but defined in Data.Functor. The Functor type class is defined as follows:
class Functor (f :: * -> *) where fmap :: (a -> b) -> f a -> f b (<$) :: a -> f b -> f a {-# MINIMAL fmap #-}
Minimal definition of Functor requires fmap to be defined.
The function fmap takes a function a -> b and takes a data type f parameterised by a. It then applies the function to the content (of the type a) to produce b, thus producing f b.
For example, we can take Maybe a, which is defined as Just a | Nothing. When we apply a function a -> b to Maybe a through fmap, we would like to apply only for the data in the constructor Just a, producing ...
Read now
Unlock full access