Why can't the type of id be specialised to (forall a. a -> a) -> (forall b. b -> b)?

前端 未结 3 2044
一向
一向 2021-02-01 16:21

Take the humble identity function in Haskell,

id :: forall a. a -> a

Given that Haskell supposedly supports impredicative polymorphism, it

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-01 16:50

    why is it expecting a type of (forall a. a -> a) -> b -> b

    I think the type forall b.(forall a. a -> a) -> b -> b is equivalent to the type you gave. It is just a canonical representation of it, where the forall is shifted as much to the left as possible.

    And the reason why it does not work is that the given type is actually more polymorphic than the type of id :: forall c. c -> c, which requires that argument and return types be equal. But the forall a in your type effectively forbids a to be unified with any other type.

提交回复
热议问题