Home > other >  What is the meaning of (`addTwo` 4) 5?
What is the meaning of (`addTwo` 4) 5?

Time:12-15

With a simple Haskell adder function

addTwo:: Num a => a -> a -> a
addTwo a b = a   b

and following expressions

addTwo 4 5 -- yields 9
4 `addTwo` 5 -- yields 9
(`addTwo` 4) 5 -- yields 9

I understand the first two expressions. However, how does the third one work? Does the expression (`addTwo` 4) become a function of one argument? What is the general principle here?

CodePudding user response:

Does the expression (`addTwo` 4) become a function of one argument?

Yes, this is exactly what happens. This is exactly the same as any other operator section like ( 4), just using backticks instead of some other infix operator. In general, (a `op`) is the same as \x -> a `op` x, while (`op` a) is the same as \x -> x `op` a.

  • Related