GHC: Ticket #5719: Empty tuple doesn't have kind Constraint
http://ghc.haskell.org/trac/ghc/ticket/5719
<p>
Bas reports that this program does not work:
</p>
<pre class="wiki">{-# LANGUAGE ConstraintKinds, TypeFamilies, FlexibleInstances #-}
module Main where
import GHC.Prim (Constraint)
import Prelude hiding (Functor, fmap)
import Data.Set (Set)
import qualified Data.Set as S (map, fromList)
class Functor f where
type C f a :: Constraint
type C f a = ()
fmap :: (C f a, C f b) => (a -> b) -> f a -> f b
instance Functor Set where
type C Set a = Ord a
fmap = S.map
instance Functor [] where
fmap = map
testList = fmap (+1) [1,2,3]
testSet = fmap (+1) (S.fromList [1,2,3])
main = do { print testList; print testSet }
</pre><p>
There's a complaint like
</p>
<pre class="wiki">Foo.hs:13:16:
Kind mis-match
Expected kind `* -> Constraint', but `()' has kind `*'
</pre>en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/5719
Trac 1.2simonpjFri, 23 Dec 2011 09:47:35 GMTdescription changed
http://ghc.haskell.org/trac/ghc/ticket/5719#comment:1
http://ghc.haskell.org/trac/ghc/ticket/5719#comment:1
<ul>
<li><strong>description</strong>
modified (<a href="/trac/ghc/ticket/5719?action=diff&version=1">diff</a>)
</li>
</ul>
<p>
This is a bug. The main delicacy in the Constraint-kind stuff is that the tuple syntax (a,b) is used for both things of kind <code>*</code> and things of kind <code>Constraint</code>. Pedro and I went to some trouble to make this work nicely, but we forgot about the empty-tuple case, which was parsed as a <code>HsTyVar</code> by the parser, rather than as an <code>HsTupleTy</code>.
</p>
<p>
I'm validating a fix now.
</p>
TicketdreixelFri, 23 Dec 2011 10:03:09 GMTcc set
http://ghc.haskell.org/trac/ghc/ticket/5719#comment:2
http://ghc.haskell.org/trac/ghc/ticket/5719#comment:2
<ul>
<li><strong>cc</strong>
<em>jpm@…</em> added
</li>
</ul>
<p>
I thought this was right. His example was different, he had:
</p>
<pre class="wiki">class Functor f where
type C f :: * -> Constraint
type C f = ()
</pre><p>
which correctly reports the kind error message you show.
</p>
<p>
The class declaration you give compiles fine. And we are converting the singleton tuple from an <code>HsTyVar</code> into an <code>HsTupleTy</code> in <a class="ext-link" href="https://github.com/ghc/ghc/blob/master/compiler/typecheck/TcHsType.lhs#L345"><span class="icon"></span>TcHsType</a>. What am I missing here?
</p>
TicketsimonpjFri, 23 Dec 2011 10:08:01 GMT
http://ghc.haskell.org/trac/ghc/ticket/5719#comment:3
http://ghc.haskell.org/trac/ghc/ticket/5719#comment:3
<p>
Aha. Confusion
</p>
<ul><li>I didn't know that <code>TcHsType</code> was doing that, and thought the error was becuase of the unit tuple thing, so I fixed the parser to do the right thing. I think that's cleaner anyway.
</li><li>After doing that I realised that the original program was wrong anyway, as you point out. So I fixed it as above.
</li><li>In fact it still didn't work becuase there was a real bug in the way default family instances were generated, so I fixed that too.
</li></ul><p>
Bottom line; you are right, but I prefer to stick with <code>HsTupleTy</code> throughout. I'll take the <code>TcHsType</code> fix out.
</p>
<p>
Simon
</p>
Ticketsimonpj@…Fri, 23 Dec 2011 17:57:49 GMT
http://ghc.haskell.org/trac/ghc/ticket/5719#comment:4
http://ghc.haskell.org/trac/ghc/ticket/5719#comment:4
<p>
commit <a class="changeset" href="http://ghc.haskell.org/trac/ghc/changeset/416c5903f3b8cf4cdd4a03c8949489df18cd790a/ghc" title="Use HsTupleTy [] for unit tuples, uniformly
This is just a tidy-up ...">416c5903f3b8cf4cdd4a03c8949489df18cd790a</a>
</p>
<pre class="wiki">Author: Simon Peyton Jones <simonpj@microsoft.com>
Date: Fri Dec 23 16:05:48 2011 +0000
Use HsTupleTy [] for unit tuples, uniformly
This is just a tidy-up triggered by #5719. We were parsing () as a
type constructor, rather than as a HsTupleTy, but it's better dealt
with uniformly as the former, I think. Somewhat a matter of taste.
compiler/hsSyn/HsTypes.lhs | 13 +++++++++++++
compiler/parser/Parser.y.pp | 30 ++++++++++++++++--------------
compiler/parser/RdrHsSyn.lhs | 22 +++++++++++-----------
compiler/typecheck/TcHsType.lhs | 12 ++++--------
4 files changed, 44 insertions(+), 33 deletions(-)
</pre>
TicketsimonpjFri, 23 Dec 2011 18:02:00 GMTstatus changed; testcase, resolution set
http://ghc.haskell.org/trac/ghc/ticket/5719#comment:5
http://ghc.haskell.org/trac/ghc/ticket/5719#comment:5
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>testcase</strong>
set to <em>indexed_types/should_run/T5719</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
Merge if you like, but I don't think its needed.
</p>
Ticket