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 it works...

The Applicative must follow these laws: 

  • Identity Law: An application of identity should not change the data:
        pure id <*> v == v
  • Homomorphism: An application of a function to a data (f x) is equivalent to the application of Applicative of the function applied to pure data (data inducted in Applicative):
       pure f <*> pure x == pure (f x)
  • Interchange: This is equivalent to saying that  f (a -> b) -> f a == f b, which should be equivalent to f ((a -> b) -> b) -> f (a -> b) == f b:
       u <*> pure y = pure ($ y) <*> u
  • Composition: Stipulates that an Applicative compose operator is similar to the function composition (.)
       pure (.) <*> u <*> v <*> w = u <*> (v <*> w)

Here, the application of the composition pure (.) <*> u ...

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