GHC: Ticket #5542: also parse class/instance declarations as "HEAD <= CONTEXT where"
http://ghc.haskell.org/trac/ghc/ticket/5542
<p>
When looking at a list of instance declarations, it can be difficult to visually locate the instance heads. In particular, the varying size of the contexts means that it's difficult to align the instance heads without introducing extraneous white-space.
</p>
<p>
I suggest allowing the head to come first (like all other declarations), so that the varying context lengths no longer prevent easy identification of the class/instance heads.
</p>
<p>
For example, I think it's easier to see which instances are being declared in this following list of (,) instances
</p>
<pre class="wiki">instance Bounded (a, b) <= (Bounded a, Bounded b) where …
instance Eq (a, b) <= (Eq a, Eq b) where …
instance Functor ((,) a) where …
instance Ord (a, b) <= (Ord a, Ord b) where …
instance Read (a, b) <= (Read a, Read b) where …
instance Show (a, b) <= (Show a, Show b) where …
</pre><p>
than it is with the default syntax
</p>
<pre class="wiki">instance (Bounded a, Bounded b) => Bounded (a, b) where …
instance (Eq a, Eq b) => Eq (a, b) where …
instance Functor ((,) a) where …
instance (Ord a, Ord b) => Ord (a, b) where …
instance (Read a, Read b) => Read (a, b) where …
instance (Show a, Show b) => Show (a, b) where …
</pre><p>
A more compelling example would involve multiparameter type classes and juxtaposition of instances for different combinations of types.
</p>
<p>
(Bonus: the proposed ordering might even help beginner grasp that the instance context is not used for instance selection.)
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/5542
Trac 1.0.1porgesWed, 12 Oct 2011 09:26:51 GMT
http://ghc.haskell.org/trac/ghc/ticket/5542#comment:1
http://ghc.haskell.org/trac/ghc/ticket/5542#comment:1
<p>
I just added <= as a reserved word into Lexer.x and then in Parser.y duplicated all mentions of => with <= as well. Doing this adds about 10 shift/reduce conflicts and 5 or so reduce/reduce conflicts.
</p>
<p>
It does compile and work, but things like this make GHC panic:
</p>
<blockquote>
<p>
instance Show a => Foo a <= Show a where
</p>
</blockquote>
<p>
:)
</p>
TicketiglooSat, 12 Nov 2011 00:29:11 GMTmilestone set
http://ghc.haskell.org/trac/ghc/ticket/5542#comment:2
http://ghc.haskell.org/trac/ghc/ticket/5542#comment:2
<ul>
<li><strong>milestone</strong>
set to <em>7.6.1</em>
</li>
</ul>
TicketsimonpjMon, 14 Nov 2011 22:20:55 GMT
http://ghc.haskell.org/trac/ghc/ticket/5542#comment:3
http://ghc.haskell.org/trac/ghc/ticket/5542#comment:3
<p>
If you can find lots of people who Really Really Want this, maybe. But however sensible in principle, it's hard to justify yet another syntactic form. I'm pretty dubious.
</p>
TicketiglooWed, 12 Sep 2012 11:12:05 GMTmilestone changed
http://ghc.haskell.org/trac/ghc/ticket/5542#comment:4
http://ghc.haskell.org/trac/ghc/ticket/5542#comment:4
<ul>
<li><strong>milestone</strong>
changed from <em>7.6.1</em> to <em>7.6.2</em>
</li>
</ul>
Ticket