What is the dot operator in Haskell?
Function composition in Haskell
In the functional programming world, everything is functions and our program consists of hundreds or maybe thousands of functions that call each other to achieve a certain goal.
We should keep functions small and each function should do one action. Because of these simple roles, function composition is very important in functional programming and is one of the most basic concepts in functional programming (and also mathematics). By composing functions, you can reuse existing functions and create a new function. let's start by describing function calling in Haskell.
Difference between function composition and Calling function
When you call a function, you apply one or more value to that function as input parameter and then that function returns the result to you. Please consider this function that gives a number and returns power 2 of that number:
You can call pow2
by sending an Integer
to this and get the result: