2

Let's say I have part of a function's signature:

f :: (a -> b) -> ...

Is there any restriction (such as their kinds) on the types of a and b?

a can't be a function, i.e. (c -> d), can it?

Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384

1 Answers1

6

a and b must have kind *, that is they must not be type constructors that require arguments. So they could be Integer, (c -> d) or Maybe String, but not (->), (a ->) or Maybe.

a can't be a function, i.e. (c -> d), can it?

Yes, it can. It can be any possible type of kind *.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
  • Ah, so when the word `type` is used, it's implied to have a `kind` of `*`? – Kevin Meredith Nov 23 '14 at 16:59
  • @KevinMeredith That may not have been technically correct on my part. I changed my wording to be more clear. – sepp2k Nov 23 '14 at 17:16
  • 1
    For an explanation of the kind `*`, see [this answer](http://stackoverflow.com/a/22807963/1186208), or [this section of the GHC 7.4.2 docs](https://downloads.haskell.org/~ghc/7.4.2/docs/html/users_guide/kind-polymorphism-and-promotion.html). (The current docs seem to have dropped that initial discussion.) I casually think of `*` as the kind of types with *values* (including function values, of course), but that may not be quite correct. – Christian Conkle Nov 23 '14 at 17:18
  • 1
    "I casually think of * as the kind of types with values (including function values, of course), but that may not be quite correct.". Perhaps it's slightly more correct to say that * is the kind of "types containing *run-time* values", since there are other kinds which contain type-level values (e.g. under GHC -XDataTypes, type-level literals 0, 1, 2 have kind Nat). Apart from this nuance, I think your intuition is valid. – Dominique Devriese Nov 23 '14 at 17:56
  • 1
    I couldn't find an existing question squarely on this topic, so I made one: [what exactly is `*`?](http://stackoverflow.com/questions/27095011/) – Christian Conkle Nov 23 '14 at 22:25