GHC: Ticket #7024: Problems with polymorphic kinds imported from module
http://ghc.haskell.org/trac/ghc/ticket/7024
<p>
There seems to be a problem when importing polymorphic kinds from a module in a cabalized package. One way to spot the problem is to <code>cabal install singletons</code>, import <code>Singletons.Lib</code> and run <code>:t SNil</code> in ghci. ghci reports a stack overflow. Another way to access (what I think is) the same error is to compile the following:
</p>
<pre class="wiki">{-# LANGUAGE TypeFamilies, DataKinds, PolyKinds, TypeOperators,
GADTs, RankNTypes #-}
import Singletons.Lib
type family Map (f :: k1 -> k2) (a :: [k1]) :: [k2]
type instance Map f '[] = '[]
type instance Map f (h ': t) = (f h) ': (Map f t)
sMap :: forall (f :: k1 -> k2) (b :: [k1]).
(forall a. Sing a -> Sing (f a)) -> Sing b -> Sing (Map f b)
sMap _ SNil = SNil
sMap f (SCons h t) = SCons (f h) (sMap f t)
</pre><p>
The error message is
</p>
<pre class="wiki"> Couldn't match kind `BOX' against `[k1]'
Kind incompatibility when matching types:
k1 :: BOX
b :: [k1]
In the pattern: SNil
In an equation for `sMap': sMap _ SNil = SNil
</pre><p>
Neither of these problems surface when checking the type of <code>SNil</code> or compiling the above code when the singletons sources are at hand and are interpreted.
</p>
<p>
I tried to make a small test case for this but was unable to reproduce the error after a number of attempts, including using Template Haskell to generate the <code>Sing</code> instance for type-level lists, as is done in the singletons library.
</p>
<p>
This was all tested on 7.5.20120620. There's a good chance this bug is related to <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/7022" title="#7022: bug: Kind variable scoping problem in Iface file when using Template Haskell (closed: fixed)">#7022</a>.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/7024
Trac 1.2.2simonpjFri, 22 Jun 2012 20:28:29 GMTdifficulty set
http://ghc.haskell.org/trac/ghc/ticket/7024#comment:1
http://ghc.haskell.org/trac/ghc/ticket/7024#comment:1
<ul>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
</ul>
<p>
I tried to <code>cabal install singletons</code> but failed:
</p>
<pre class="wiki">$ cabal install --with-compiler=c:/code/HEAD-2/inplace/bin/ghc-stage2 singletons
Resolving dependencies...
cabal.exe: cannot configure syb-0.3.6.1. It requires base >=4.0 && <4.6
For the dependency on base >=4.0 && <4.6 there are these packages:
base-4.0.0.0, base-4.1.0.0, base-4.2.0.0, base-4.2.0.1, base-4.2.0.2,
base-4.3.0.0, base-4.3.1.0, base-4.4.0.0, base-4.4.1.0, base-4.5.0.0 and
base-4.5.1.0. However none of them are available.
base-4.0.0.0 was excluded because array-0.3.0.3 requires base >=4.2 && <5
base-4.0.0.0 was excluded because template-haskell-2.6.0.0 requires base >=4.2
&& <5
base-4.0.0.0 was excluded because containers-0.5.0.0 requires base >=4.2 && <5
base-4.0.0.0 was excluded because base-4.6.0.0 was selected instead
base-4.0.0.0 was excluded because of the top level dependency base -any
base-4.1.0.0 was excluded because array-0.3.0.3 requires base >=4.2 && <5
base-4.1.0.0 was excluded because template-haskell-2.6.0.0 requires base >=4.2
&& <5
base-4.1.0.0 was excluded because containers-0.5.0.0 requires base >=4.2 && <5
base-4.1.0.0 was excluded because base-4.6.0.0 was selected instead
base-4.1.0.0 was excluded because of the top level dependency base -any
base-4.2.0.0 was excluded because base-4.6.0.0 was selected instead
base-4.2.0.0 was excluded because of the top level dependency base -any
base-4.2.0.1 was excluded because base-4.6.0.0 was selected instead
base-4.2.0.1 was excluded because of the top level dependency base -any
base-4.2.0.2 was excluded because base-4.6.0.0 was selected instead
base-4.2.0.2 was excluded because of the top level dependency base -any
base-4.3.0.0 was excluded because base-4.6.0.0 was selected instead
base-4.3.0.0 was excluded because of the top level dependency base -any
base-4.3.1.0 was excluded because base-4.6.0.0 was selected instead
base-4.3.1.0 was excluded because of the top level dependency base -any
base-4.4.0.0 was excluded because base-4.6.0.0 was selected instead
base-4.4.0.0 was excluded because of the top level dependency base -any
base-4.4.1.0 was excluded because base-4.6.0.0 was selected instead
base-4.4.1.0 was excluded because of the top level dependency base -any
base-4.5.0.0 was excluded because base-4.6.0.0 was selected instead
base-4.5.0.0 was excluded because of the top level dependency base -any
base-4.5.1.0 was excluded because base-4.6.0.0 was selected instead
base-4.5.1.0 was excluded because of the top level dependency base -any
</pre><p>
I manually deleted the dependency on <code>syb</code> (thinking I could comment out the code that depended on <code>syb</code> but that still failed:
</p>
<pre class="wiki">$ cabal install --with-compiler=c:/code/HEAD-2/inplace/bin/ghc-stage2
Resolving dependencies...
Downloading mtl-2.1.1...
Configuring mtl-2.1.1...
Preprocessing library mtl-2.1.1...
Building mtl-2.1.1...
[ 1 of 21] Compiling Control.Monad.Writer.Class ( Control\Monad\Writer\Class.hs, dist\build\Control\Monad\Writer\Class.o
)
[ 2 of 21] Compiling Control.Monad.State.Class ( Control\Monad\State\Class.hs, dist\build\Control\Monad\State\Class.o )
[ 3 of 21] Compiling Control.Monad.Reader.Class ( Control\Monad\Reader\Class.hs, dist\build\Control\Monad\Reader\Class.o
)
[ 4 of 21] Compiling Control.Monad.RWS.Class ( Control\Monad\RWS\Class.hs, dist\build\Control\Monad\RWS\Class.o )
[ 5 of 21] Compiling Control.Monad.Identity ( Control\Monad\Identity.hs, dist\build\Control\Monad\Identity.o )
[ 6 of 21] Compiling Control.Monad.Error.Class ( Control\Monad\Error\Class.hs, dist\build\Control\Monad\Error\Class.o )
Control\Monad\Error\Class.hs:93:18: Not in scope: `catch'
cabal.exe: Error: some packages failed to install:
mtl-2.1.1 failed during the building phase. The exception was:
ExitFailure 1
singletons-0.8 depends on mtl-2.1.1 which failed to install.
</pre><p>
So I'm stuck at the first fence.
</p>
<p>
GHC should never be unifying BOX with <code>[k]</code>. They belong to different levels. Something is badly wrong. I am eager to reproduce it.
</p>
TicketgoldfireSat, 23 Jun 2012 02:54:09 GMT
http://ghc.haskell.org/trac/ghc/ticket/7024#comment:2
http://ghc.haskell.org/trac/ghc/ticket/7024#comment:2
<p>
I ran into those two problems as well with the recent version of GHC, but I thought the problems were local. Here are the fixes I used (package maintainers already notified):
</p>
<ul><li>For the syb problem, change syb.cabal to allow a greater range of version numbers for the base package. I changed my file to allow <code>base >= 4.0 && < 5.0</code> and it worked.
</li><li>For the mtl package, you'll need to edit Control/Monad/Error/Class.hs. Add <code>catch</code> to the import list from <code>Control.Exception</code> on line 55.
</li></ul><p>
I believe these were the only package-related problems I had, so these fixes should allow you to proceed.
</p>
TicketgoldfireSat, 23 Jun 2012 14:43:36 GMT
http://ghc.haskell.org/trac/ghc/ticket/7024#comment:3
http://ghc.haskell.org/trac/ghc/ticket/7024#comment:3
<p>
Both the mtl and syb packages have been updated since my last comment (to versions 2.1.2 and 0.3.6.2, respectively) and now work without a hiccup. Thanks, Edward Kmett and José Pedro Magalhães!
</p>
Ticketsimonpj@…Tue, 10 Jul 2012 15:21:45 GMT
http://ghc.haskell.org/trac/ghc/ticket/7024#comment:4
http://ghc.haskell.org/trac/ghc/ticket/7024#comment:4
<p>
commit <a class="changeset" href="http://ghc.haskell.org/trac/ghc/changeset/3fe3ef509627cb8c9aa7751beb44d1b4408f8b22/ghc" title="More changes to kind inference for type and class declarations
These ...">3fe3ef509627cb8c9aa7751beb44d1b4408f8b22</a>
</p>
<pre class="wiki">Author: Simon Peyton Jones <simonpj@microsoft.com>
Date: Tue Jul 10 16:02:03 2012 +0100
More changes to kind inference for type and class declarations
These should fix #7024 and #7022, among others.
The main difficulty was that we were getting occ-name clashes
between kind and type variables in TyCons, when spat into an
interface file. The new scheme is to tidy TyCons during the
conversoin into IfaceSyn, rather than trying to generate them
pre-tidied, which was the already-unsatisfactory previous plan.
There is the usual wave of refactorig as well.
compiler/iface/MkIface.lhs | 129 +++++++++++++++++++++-----------
compiler/typecheck/TcHsType.lhs | 143 ++++++++++++++++++++---------------
compiler/typecheck/TcRnDriver.lhs | 8 +-
compiler/typecheck/TcRnTypes.lhs | 40 +++++++---
compiler/typecheck/TcRules.lhs | 3 +-
compiler/typecheck/TcTyClsDecls.lhs | 110 +++++++++++++-------------
compiler/types/Kind.lhs | 9 ++-
7 files changed, 267 insertions(+), 175 deletions(-)
</pre>
TicketsimonpjThu, 12 Jul 2012 16:51:43 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/7024#comment:5
http://ghc.haskell.org/trac/ghc/ticket/7024#comment:5
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
It's fixed by the above patch.
</p>
<p>
The test for <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/7022" title="#7022: bug: Kind variable scoping problem in Iface file when using Template Haskell (closed: fixed)">#7022</a> will do for this one. I don't want a regression test that is so elaborate!
</p>
<p>
Simon
</p>
Ticket