Friday, 29 April 2016

Haskell: Functions take priority over anything else


In Haskell functions take more priority than anything else. For example 'square x = x*x' return the square of x. What will be the value of square 5*2, well you may tell square 5*2 = square 10 =  10 * 10 = 100. But once you evaluate square 5*2, you will get 50.
Prelude> let square x = x*x
Prelude> 
Prelude> square 5*2
50

Why square 5*2 returns 50?
It is because, functions take more pririty. So the expression 'square 5*2' evaluated like below.

square 5*2 = (5 * 5) * 2 = 25 * 2 = 50




Previous                                                 Next                                                 Home

No comments:

Post a Comment