- Create a new project working-with-applicative with the simple Stack template:
stack new working-with-applicative simple
- Open src/Main.hs and add the following imports after the initial module definition. The Applicative type class is defined in the module Control.Applicative:
import Data.Functor import Control.Applicative
- We will use two operators, Functor application <$> (synonym for fmap) and Applicative application <*>. The Applicative function <*> is defined as <*> :: f (a -> b) -> f a -> f b. It takes a data type where values are functions of type (a -> b) and applies to a data type with values of type a, and gets back the data type with values of type b. In the first example, we will use a list:
-- Mapping ...