Commit 2da06d7c authored by's avatar

User manual update, as prodded by #10760.

This clarifies that kind variables are inputs to type families
and can be used to distinguish instances.
parent b4ed1300
......@@ -6248,6 +6248,17 @@ F IO Bool -- WRONG: kind mismatch in the first argument
F Bool -- WRONG: unsaturated application
The result kind annotation is optional and defaults to
<literal>*</literal> (like argument kinds) if
omitted. Polykinded type families can be
declared using a parameter in the kind annotation:
type family F a :: k
In this case the kind parameter <literal>k</literal> is actually an implicit
parameter of the type family.
<sect3 id="type-instance-declarations">
......@@ -6365,7 +6376,7 @@ type instance G Int Char Float = Double -- WRONG: must be two type parameters
are restricted to be <firstterm>compatible</firstterm>. Two type patterns
are compatible if
<listitem><para>all corresponding types in the patterns are <firstterm>apart</firstterm>, or</para></listitem>
<listitem><para>all corresponding types and implicit kinds in the patterns are <firstterm>apart</firstterm>, or</para></listitem>
<listitem><para>the two patterns unify producing a substitution, and the right-hand sides are equal under that substitution.</para></listitem>
Two types are considered <firstterm>apart</firstterm> if, for all possible
......@@ -6394,6 +6405,16 @@ type instance G (Char, a) = [a] -- ILLEGAL overlap, as [Char] /= [Int]
is associated or not, and it is not only a matter of consistency, but
one of type safety. </para>
<para>For a polykinded type family, the kinds are checked for
apartness just like types. For example, the following is accepted:
type family J a :: k
type instance J Int = Bool
type instance J Int = Maybe
These instances are compatible because they differ in their implicit kind parameter; the first uses <literal>*</literal> while the second uses <literal>* -> *</literal>.</para>
The definition for "compatible" uses a notion of "apart", whose definition
in turn relies on type family reduction. This condition of "apartness", as
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment