<div>If I define the following</div><div><br></div><div><font face="courier new, monospace">{-# LANGUAGE FunctionalDependencies, GADTs, KindSignatures, MultiParamTypeClasses, PolyKinds, RankNTypes, TypeOperators, DefaultSignatures, DataKinds, FlexibleInstances, UndecidableInstances #-}</font></div>
<div><font face="courier new, monospace">module Indexed.Test where</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">class IMonad (m :: (k -&gt; *) -&gt; k -&gt; *) </font><span style="font-family:&#39;courier new&#39;,monospace">where </span></div>
<div><span style="font-family:&#39;courier new&#39;,monospace">  ireturn :: a x -&gt; m a x</span></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">infixr 5 :-</font></div>
<div><font face="courier new, monospace">data Thrist :: ((i,i) -&gt; *) -&gt; (i,i) -&gt; * where</font></div><div><font face="courier new, monospace">  Nil :: Thrist a &#39;(i,i)</font></div><div><font face="courier new, monospace">  (:-) :: a &#39;(i,j) -&gt; Thrist a &#39;(j,k) -&gt; Thrist a &#39;(i,k)</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">instance IMonad Thrist where</font></div><div><font face="courier new, monospace">  ireturn a = a :- Nil</font></div><div>
<font face="courier new, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">Then &#39;ireturn&#39; complains (correctly) that it can&#39;t match the k with the kind (i,i). The reason it can&#39;t is because when you look at the resulting signature for the MPTC it generates it looks like</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><div><div><font face="courier new, monospace">class IMonad k m where</font></div><div><font face="courier new, monospace">  ireturn :: a x -&gt; m a x</font></div>
</div></div><div><br></div><div><font face="arial, helvetica, sans-serif">However, there doesn&#39;t appear to be a way to say that the kind k should be determined by m. </font></div><div><font face="arial, helvetica, sans-serif"><br>
</font></div><div><font face="arial, helvetica, sans-serif">I tried doing:</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><div><font face="courier new, monospace">class IMonad (m :: (k -&gt; *) -&gt; k -&gt; *) | m -&gt; k </font><span style="font-family:&#39;courier new&#39;,monospace">where </span></div>
<div><span style="font-family:&#39;courier new&#39;,monospace">  ireturn :: a x -&gt; m a x</span></div></div><div><br></div><div><font face="arial, helvetica, sans-serif">Surprisingly (to me) this compiles and generates the correct constraints for IMonad:</font></div>
<div><br></div><div><div><font face="courier new, monospace">ghci&gt; :set -XPolyKinds -XKindSignatures -XFunctionalDependencies -XDataKinds -XGADTs</font></div><div><div><font face="courier new, monospace">ghci&gt; class IMonad (m :: (k -&gt; *) -&gt; k -&gt; *) | m -&gt; k where ireturn :: a x -&gt; m a x</font></div>
<div><font face="courier new, monospace">ghci&gt; :info IMonad</font></div><div><font face="courier new, monospace">class IMonad k m | m -&gt; k where</font></div><div><font face="courier new, monospace">  ireturn :: a x -&gt; m a x</font></div>
</div><div><br></div><div>But when I add </div><div><br></div><div><font face="courier new, monospace">ghci&gt; :{</font></div><div><font face="courier new, monospace">Prelude| data Thrist :: ((i,i) -&gt; *) -&gt; (i,i) -&gt; * where</font></div>
<div><font face="courier new, monospace">Prelude|   Nil :: Thrist a &#39;(i,i)</font></div><div><font face="courier new, monospace">Prelude|   (:-) :: a &#39;(i,j) -&gt; Thrist a &#39;(j,k) -&gt; Thrist a &#39;(i,k)</font></div>
<div><font face="courier new, monospace">Prelude| :}</font></div><div><span style="font-family:&#39;courier new&#39;,monospace"><br></span></div><div><div>and attempt to introduce the instance, I crash:</div></div><div><span style="font-family:&#39;courier new&#39;,monospace"><br>
</span></div><div><span style="font-family:&#39;courier new&#39;,monospace">ghci&gt; instance IMonad Thrist where ireturn a = a :- Nil</span></div><div><font face="courier new, monospace">ghc: panic! (the &#39;impossible&#39; happened)</font></div>
<div><font face="courier new, monospace">  (GHC version 7.6.0.20120810 for x86_64-apple-darwin):</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">        </span>lookupVarEnv_NF: Nothing</font></div>
<div><br></div><div><font face="courier new, monospace">Please report this as a GHC bug:  <a href="http://www.haskell.org/ghc/reportabug">http://www.haskell.org/ghc/reportabug</a></font></div></div><div><font face="courier new, monospace"><br>
</font></div><div>Moreover, attempting to compile them in separate modules leads to a different issue. </div><div><br></div><div>Within the module, IMonad has a type that includes the kind k and the constraint on it from m. But from the other module, :info shows no such constraint, and the above code again fails to typecheck, but upon trying to recompile, when GHC goes to load the IMonad instance from the core file, it panicks again differently about references to a variable not present in the core.</div>
<div><br></div><div>Is there any way to make such a constraint that determines a kind from a type parameter in GHC 7.6 at this time?</div><div><br></div><div>I tried the Kind hack used in GHC.TypeLits, but it doesn&#39;t seem to be applicable to this situation.</div>
<div><br></div><div>-Edward</div>