September 2017
Beginner to intermediate
396 pages
9h 46m
English
The Applicative type class is defined as follows:
class Functor f => Applicative (f :: * -> *) where pure :: a -> f a (<*>) :: f (a -> b) -> f a -> f b (*>) :: f a -> f b -> f b (<*) :: f a -> f b -> f a {-# MINIMAL pure, (<*>) #-}
The minimal definition of an Applicative instance requires at least pure and <*> to be defined. The definition also implies that we can define an instance of an Applicative for f only if f is also an instance of a Functor.
The pure function takes a value and creates a data type. For example, in the context of List, Maybe, and Either, the pure function will fetch the following values:
pure 10 :: [Int] = [10] -- in the context of List pure 10 :: Maybe Int = Just 10 -- in the context of Maybe pure ...
Read now
Unlock full access