George
George

Reputation: 7327

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 $.

Upvotes: 4

Views: 88

Answers (1)

chi
chi

Reputation: 116174

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.

Upvotes: 15

Related Questions