? The type signature for is $as follows: ($) :: (a -> b) -> a -> b Thus, if plus1...">

Why does this form not 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 why then

> ($ 1) plus1
2

and? The form ($ 1) plus1apparently violates the type signature for $.

+4
source share
1 answer

If you try

(($) 1) plus1

you will get the expected type error.

A special syntax ($ 1)is called a section and denotes \x -> x $ 1that differs from a simple application ($) 1. This syntax can be used with all infix operators (*), for example. (+ 1)or (* 4).

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

+15
source

Source: https://habr.com/ru/post/1664847/


All Articles