What is the assumption made in “Learn You a Haskell” when deducing the kind?

前端 未结 2 1800
醉话见心
醉话见心 2021-02-18 22:52

This question is not subjective. A very specific verb is used in the referenced book, and I\'d like to understand what the implication of that phrasing is, because I\'m afraid I

相关标签:
2条回答
  • 2021-02-18 22:57

    In fact, the compiler does assume! But you can ask it not to with the PolyKinds extension. You can read about it in more detail here. With that extension turned on, the kind of Barry will be forall k. (k -> *) -> k -> * -> *.

    0 讨论(0)
  • 2021-02-18 23:00

    Good point. The author makes a needless assumtion. Perhaps just to make it easier to understand in his Type Foo chapter but people like yourself may rightfully question this.

    Both t, k and p are type variables. As we see from yabba :: p it can live alone so it's like a constant function, as if it was a value instead of a type, it's type signature would say Int or Char, whatever... you name it. But since it is a type then it's kind signature is *.

    However t type here takes a type variable k to construct a type (dabba :: t k) so we are sure that (no assumtion here) t has a kind signature like * -> * and k has *.

    Once we know this... the type Barry t k p's kind signature is (* -> *) -> * -> * -> * which means it takes t then k and then p and give us Barry type.

    Edit Make sure to read @luqui's comment below.

    0 讨论(0)
提交回复
热议问题