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

  1. The first data type Func takes two arguments, a and b. The data definition simply encapsulates it inside as Func (a -> b). Here, (a -> b) represents the function type that takes a as an argument and produces a value of type b.
  2. The function compose simply extracts the functions encapsulated in Func a b and Func b c and composes them with the (.) function. 
The function (.) is called function composition, and it is used to compose functions without having to specify. It can be simply defined as (.) g f x = g (f x). Also, note when we use function composition, we do not have to specify an argument to the function. This is called a point-free style of programming. At times, a point-free style may be clearer to understand.

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