Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic function composition in Haskell

I was reading here, and I noticed that, for example, if I have the following function definitions:

a :: Integer->Integer->Integer
b :: Integer->Bool

The following expression is invalid:

(b . a) 2 3

It's quite strange that the functions of the composition must have only one parameter.

Is this restriction because some problem in defining the most generic one in Haskell or have some other reason?

I'm new to Haskell, so I'm asking maybe useless questions.

like image 869
hsknew Avatar asked Dec 29 '10 04:12

hsknew


1 Answers

When you do a 2 3, you're not applying a to 2 arguments. You're actually applying a to it's only argument, resulting in a function, then take that function and apply it to 3. So you actually do 2 applications. So in a sense, what you have is not equivalent to this:

a :: (Integer, Integer) -> Integer
b :: Integer -> Integer
(b . a) (2, 3)

You could've done this, btw

(b . a 2) 3
like image 181
Phil Avatar answered Oct 13 '22 10:10

Phil