Opened 6 years ago

Closed 2 years ago

#5542 closed feature request (invalid)

also parse class/instance declarations as "HEAD <= CONTEXT where"

Reported by: nfrisby Owned by:
Priority: normal Milestone:
Component: Compiler (Parser) Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


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.

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.

For example, I think it's easier to see which instances are being declared in this following list of (,) instances

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 …

than it is with the default syntax

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 …

A more compelling example would involve multiparameter type classes and juxtaposition of instances for different combinations of types.

(Bonus: the proposed ordering might even help beginner grasp that the instance context is not used for instance selection.)

Change History (8)

comment:1 Changed 6 years ago by porges

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.

It does compile and work, but things like this make GHC panic:

instance Show a => Foo a <= Show a where


comment:2 Changed 6 years ago by igloo

Milestone: 7.6.1

comment:3 Changed 6 years ago by simonpj

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.

comment:4 Changed 5 years ago by igloo


comment:5 Changed 3 years ago by thoughtpolice


Moving to 7.10.1.

comment:6 Changed 3 years ago by thoughtpolice


Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:7 Changed 2 years ago by thomie

Milestone: 7.12.1

Please try to get support for this feature on one of the mailing lists first. See also: WorkingConventions/AddingFeatures.

comment:8 Changed 2 years ago by thomie

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.