Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

haskell

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

like image 759
George Avatar asked Dec 05 '22 16:12

George


1 Answers

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.

like image 159
chi Avatar answered Dec 09 '22 13:12

chi