this question has answer here:
- kind signatures 1 answer
can explain or give link explaining * -> * part of code below?
data binarytree t :: * -> * leaf :: binarytree empty branch :: -> binarytree isempty -> binarytree isempty' -> binarytree nonempty thanks lot.
kind signatures. can used explicitly define arity of type constructor. * means "any type", , rest works kind of normal function types.in case, have partial application:
binarytree t :: * -> * means "binarytree t function types types", makes sense, since can apply 1 other type:
f :: (binarytree t) -> (binarytree t) b * -> * * * -> * * the binarytree t part applied type a, giving type binarytree t :: *. (binarytree t) alone not applied yet, having kind * -> *, , still need apply simple type. (this works same way when f 1 still has type int -> int when f :: int -> int -> int)
note can mix normal "arity declarations", mentioning type's parameters, implicit, , kind signatures, done here. have written binarytree follows:
data binarytree t -- normal variant or this:
data binarytree :: * -> * -> * -- "kinded" in both cases, compiler knows binarytree going take 2 type parameters.
and for? first, is described in link, need or want explicitly declare how many type parameters type should take. maybe more interesting case occurs when use diffent kinds * (aka datakinds). @ this:
data empty = empty | nonempty data binarytree (t :: empty) (a :: *) :: * -- ... oh, , ghci lets @ kinds, in case unsure. works same way :t:
prelude> :k either either :: * -> * -> *
Comments
Post a Comment