diff options
author | Richard Eisenberg <eir@cis.upenn.edu> | 2014-01-10 10:06:53 -0500 |
---|---|---|
committer | Richard Eisenberg <eir@cis.upenn.edu> | 2014-01-10 16:12:33 -0500 |
commit | 0369c9745e2ce66f4c2d817a3aa9f2487395e0c7 (patch) | |
tree | 1f5c274f7250f6accb2ea9b5ff2d7d4aa22c3482 /docs | |
parent | 3c2ae51425df91ed7c25aa6f6dc344c8a0089e99 (diff) | |
download | haskell-0369c9745e2ce66f4c2d817a3aa9f2487395e0c7.tar.gz |
Clarify issue in #8630 in users' guide.
We do *not* propagate kind information from an instance declaration's
members back into the instance head.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/users_guide/glasgow_exts.xml | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index e97faf1edb..d62f9953af 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -6069,6 +6069,35 @@ type family SafeHead where -- SafeHead :: [k] -> Maybe k </para> </sect2> + +<sect2><title>Kind inference in class instance declarations</title> + +<para>Consider the following example of a poly-kinded class and an instance for it:</para> + +<programlisting> +class C a where + type F a + +instance C b where + type F b = b -> b +</programlisting> + +<para>In the class declaration, nothing constrains the kind of the type +<literal>a</literal>, so it becomes a poly-kinded type variable <literal>(a :: k)</literal>. +Yet, in the instance declaration, the right-hand side of the associated type instance +<literal>b -> b</literal> says that <literal>b</literal> must be of kind <literal>*</literal>. GHC could theoretically propagate this information back into the instance head, and +make that instance declaration apply only to type of kind <literal>*</literal>, as opposed +to types of any kind. <emphasis>However, GHC does not do this.</emphasis></para> + +<para>In short: GHC does <emphasis>not</emphasis> propagate kind information from +the members of a class instance declaration into the instance declaration head.</para> + +<para>This lack of kind inference is simply an engineering problem within GHC, but +getting it to work would make a substantial change to the inference infrastructure, +and it's not clear the payoff is worth it. If you want to restrict <literal>b</literal>'s +kind in the instance above, just use a kind signature in the instance head.</para> + +</sect2> </sect1> <sect1 id="promotion"> |