O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Create a new project working-with-applicative with the simple Stack template:
        stack new working-with-applicative simple
  1. 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
  1. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required