What does * (star) or other species mean in the haddock instance list

Viewing Haddock of Various Packages I often come up with instance documents that look like this ( Control.Category ):

Category k (Coercion k) Category * (->) 

or this ( Control.Monad.Trans.Identity ):

 MonadTrans (IdentityT *) 

What exactly does the view signature mean? It does not appear in the source, but I already noticed that this happens in modules that use the PolyKinds extension. I suspect this is similar to TypeApplication, but with a view. So, for example, the last example means that IdentityT is a monad converter if the first argument is * .

So my questions are:

  • Is my interpretation correct and what exactly does the reference signature mean?
  • In the first instance of Category , how should I know that k is a view, not a type? Or do I just need to know the arity of Category ?
  • What is the source code similar to this syntax?

I do not ask for an explanation of the species.

+5
source share
1 answer

To quote a recent post by Richard Eisenberg on the haskell-cafe mailing list :

Sometimes Haddock tries to handle types with -XPolyKinds . The problem is that GHC usually does not require type arguments to be written and they do not print them (unless you say -fprint-explicit-kinds ). But I think Haddock prints views when -XPolyKinds turned on. Thus, two different definitions are really the same: just one module has -XPolyKinds , and the other does not.

* - type of ordinary types. So, Int has the form * (we write Int :: * ), and Maybe has the form * -> * . Typeable actually has the form forall k. k -> Constraint forall k. k -> Constraint , which means it is polished. In the first snippet below, the argument * to Typeable creates an instance of k using * , because a variable of type a has the form * .

So, you guessed it, this is due to PolyKinds . Haddock displays these multi-type types with a kind of "explicit view of the application." It so happened that Category is multi-like, having the form forall k. (k -> k -> *) -> Constraint forall k. (k -> k -> *) -> Constraint , so Haddock displays a view application next to each instance.

In my opinion, this is a mistake or inadequacy of Haddock, since, as far as I know, there is no analogue of the source code. This is confusing, and I don’t know a better way to understand this than to recognize the way in which it usually manifests and to visually infer what comes from the context.

+4
source

Source: https://habr.com/ru/post/1263133/


All Articles