Kind Signatures

前端 未结 1 666
情话喂你
情话喂你 2020-12-10 13:02

I am going through the Haskell wiki books GADTS

https://en.wikibooks.org/wiki/Haskell/GADT guide.

I was tracking pretty well until a Kind signature was added

相关标签:
1条回答
  • 2020-12-10 13:28

    The same way a type signature works for values, a kind signature works for types.

    f :: Int -> Int -> Bool
    f x y = x < y
    

    Here, f takes two argument values and produces a result value. The equivalent for types could be:

    data D a b = D a b
    

    The type D takes two argument types and produces a result type (it is * -> * -> *). For example, D Int String is a type (which has kind *). The partial application D Int has kind * -> *, just the same way the partial application f 15 has type Int -> Bool.

    So we could rewrite the above as:

    data D :: * -> * -> * where
      D :: a -> b -> D a b
    

    In GHCi, you can query types and kinds:

    > :type f
    f :: Int -> Int -> Bool
    > :kind D
    D :: * -> * -> *
    
    0 讨论(0)
提交回复
热议问题