Opened 5 years ago

Last modified 4 years ago

#3490 new feature request

Relax superclass restrictions

Reported by: simonpj Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.10.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Doaitse points out that we currently reject

class C a b | a -> b where

class C a b => D a  where

on the grounds that 'b' is not in scope in the second class decl. (Only type variables in the "head", namely (D a), can be mentioned in the superclass context.) My response to him was as follows.

The easiest way forward is to re-express your program using type functions. Then class C will have just a single type parameter (a), with the 'b' part being expressed by a type function. That would resolve the problem rather nicely.

Medium term, I think the Right Thing is to allow a class declaration

class Q => C a b

(where Q is a context) if and only iff the type

forall ab. Q => C a b

is unambiguous. What does "unambiguous" mean? As it happens, we are working on nailing that down right now. For example, here is a stupid but unambiguous declaration:

type family F a
class (b ~ F a, Eq b) => C a

I do not know of any non-stupid examples that would be rejected by the current rule, but there might be some.
I'll open a ticket because I'd like to get to this when we have the other pieces working.

Change History (4)

comment:1 Changed 5 years ago by claus

This sounded familiar. See #714 .

comment:2 Changed 5 years ago by simonpj

Dead right -- thanks.

comment:3 Changed 4 years ago by simonmar

So should this be closed as a duplicate?

comment:4 Changed 4 years ago by simonpj

  • Type changed from bug to feature request

Actually I'll close #714 in favour of this ticket. #714 has an interesting discussion but it wanders around a bit, whereas this ticket now focuses on the actual feature request.

Simon

Note: See TracTickets for help on using tickets.