Type of functions that can be passed as parameters

Think of the types in this calculation deeply, really deeply

id id

From right to left, the first id is of type

 a -> a

this means that the second id that takes the first argument must be of type

(a -> a) -> (a -> a)

Types do not match! OK, you could say that the first id had this later type, however it would make the second id type

((a -> a) -> (a -> a)) -> ((a -> a) -> (a -> a))

I thought it was encouraging that functions can have generic or variable types, functions that are associated with some in the calculation. As I see it, it seems that a new function is iddefined for each call.

+4
source share
2

. id . , . , , - , id "Hello" ++ show (id 5). id :: String -> String. id :: Integer -> Integer ( , ). , , id - - , .

, . id - . , , - , .

, , GHC. , id , . , , id.

+8

.

id x = x

∀α. α → α, " α, id α α".

id id

:

  • id ∀α. α → α,
  • id ∀β. β → β, α β, ,
  • α id ∀β. β → β, , id ∀β. β → β ∀β. β → β,
  • ok ∀β. β → β, ∀α. α → α.

. : System F.

+3

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


All Articles