当前位置: 动力学知识库 > 问答 > 编程问答 >

haskell - Why doesn't this form violate the type signature for `$`?

问题描述:

The type signature for $ is as follows:

($) :: (a -> b) -> a -> b

Thus if plus1 n = n + 1, then we have that

> ($) plus1 1

2

But then why is it that

> ($ 1) plus1

2

as well? The form ($ 1) plus1 seems to violate the type signature for $.

网友答案:

If you try

(($) 1) plus1

you will get the type error you expect.

The special syntax ($ 1) is called a section, and stands for \x -> x $ 1, which differs from the plain application ($) 1. This syntax can be used with all infix operators (*) e.g. (+ 1) or (* 4).

(*) Except -, since (- 10) is the negative constant -10.

分享给朋友:
您可能感兴趣的文章:
随机阅读: