开发者

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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜